********************************************************************************
** 	TITLE:		gb1987_bes_contact_networks		                              **
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       f655a-f655h							                          **
**	DATE:		October 2022 					                              **	
**	VERSION:	Stata 16					                                  **
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close
log using "gb1987_bes_contact_networks", replace

* Create file to link pano to constituencies

import excel using "pano1987.xlsx", sheet(pano1987) firstrow clear

drop if pano == .

save "panoBES1987.dta", replace

* Open dataset

use "f655b.dta", clear

rename int intnb

save "f655b2.dta", replace

use "f655d.dta", clear

rename int intnb

save "f655d2.dta", replace

use "f655e.dta", clear

rename int intnb

save "f655e2.dta", replace

use "f655f.dta", clear

rename int intnb

save "f655f2.dta", replace

use "f655g.dta", clear

rename int intnb

save "f655g2.dta", replace

use "f655h.dta", clear

rename int intnb

save "f655h2.dta", replace

append using f655a f655b2 f655c f655d2 f655e2 f655f2 f655g2 f655h2

* Link pano to constituencies

merge m:1 pano using panoBES1987


***********************
** DISTRICT OUTCOMES **
***********************

* Only districts with pano available in the 1987 BES cross-section survey codebook (see pages 185-201) are included

* Clean district names

gen district_name = constituency
replace district_name = upper(district_name)

* Note: 1 = Conservative, 2 = Labour, 3 = Alliance, 4 = SNP/Plaid Cymru

gen district_outcome = .

replace district_outcome = 1 if district_name == "LUTON SOUTH"
replace district_outcome = 1 if district_name == "BEDFORDSHIRE MID"
replace district_outcome = 1 if district_name == "BEDFORDSHIRE NORTH"
replace district_outcome = 1 if district_name == "LUTON NORTH"
replace district_outcome = 1 if district_name == "BEDFORDSHIRE SOUTH WEST"
replace district_outcome = 1 if district_name == "BERKSHIRE EAST"
replace district_outcome = 1 if district_name == "NEWBURY"
replace district_outcome = 1 if district_name == "READING EAST"
replace district_outcome = 1 if district_name == "READING WEST"
replace district_outcome = 1 if district_name == "SLOUGH"
replace district_outcome = 1 if district_name == "WINDSOR & MAIDENHEAD"
replace district_outcome = 1 if district_name == "WOKINGHAM"
replace district_outcome = 1 if district_name == "AYLESBURY"
replace district_outcome = 1 if district_name == "BEACONSFIELD"
replace district_outcome = 1 if district_name == "BUCKINGHAM"
replace district_outcome = 1 if district_name == "CHESHAM & AMERSHAM"
replace district_outcome = 1 if district_name == "MILTON KEYNES"
replace district_outcome = 1 if district_name == "WYCOMBE"
replace district_outcome = 1 if district_name == "BEXHILL & BATTLE"
replace district_outcome = 1 if district_name == "BRIGHTON KEMPTOWN"
replace district_outcome = 1 if district_name == "BRIGHTON PAVILION"
replace district_outcome = 1 if district_name == "EASTBOURNE"
replace district_outcome = 1 if district_name == "HASTINGS & RYE"
replace district_outcome = 1 if district_name == "HOVE"
replace district_outcome = 1 if district_name == "LEWES"
replace district_outcome = 1 if district_name == "WEALDEN"
replace district_outcome = 1 if district_name == "BASILDON"
replace district_outcome = 1 if district_name == "BILLERICAY"
replace district_outcome = 1 if district_name == "BRAINTREE"
replace district_outcome = 1 if district_name == "BRENTWOOD & ONGAR"
replace district_outcome = 1 if district_name == "CASTLE POINT"
replace district_outcome = 1 if district_name == "CHELMSFORD"
replace district_outcome = 1 if district_name == "EPPING FOREST"
replace district_outcome = 1 if district_name == "HARLOW"
replace district_outcome = 1 if district_name == "HARWICH"
replace district_outcome = 1 if district_name == "COLCHESTER NORTH"
replace district_outcome = 1 if district_name == "ROCHFORD"
replace district_outcome = 1 if district_name == "SAFFRON WALDEN"
replace district_outcome = 1 if district_name == "COLCHESTER SOUTH & MALDON"
replace district_outcome = 1 if district_name == "SOUTHEND EAST"
replace district_outcome = 1 if district_name == "SOUTHEND WEST"
replace district_outcome = 1 if district_name == "THURROCK"
replace district_outcome = 1 if district_name == "ALDERSHOT"
replace district_outcome = 1 if district_name == "BASINGSTOKE"
replace district_outcome = 1 if district_name == "HAMPSHIRE EAST"
replace district_outcome = 1 if district_name == "EASTLEIGH"
replace district_outcome = 1 if district_name == "FAREHAM"
replace district_outcome = 1 if district_name == "GOSPORT"
replace district_outcome = 1 if district_name == "HAVANT"
replace district_outcome = 1 if district_name == "ISLE OF WIGHT"
replace district_outcome = 1 if district_name == "NEW FOREST"
replace district_outcome = 1 if district_name == "HAMPSHIRE NORTH WEST"
replace district_outcome = 1 if district_name == "PORTSMOUTH NORTH"
replace district_outcome = 1 if district_name == "PORTSMOUTH SOUTH"
replace district_outcome = 1 if district_name == "ROMSEY & WATERSIDE"
replace district_outcome = 1 if district_name == "SOUTHAMPTON ITCHEN"
replace district_outcome = 1 if district_name == "SOUTHAMPTON TEST"
replace district_outcome = 1 if district_name == "WINCHESTER"
replace district_outcome = 1 if district_name == "BROXBOURNE"
replace district_outcome = 1 if district_name == "HERTFORD & STORTFORD"
replace district_outcome = 1 if district_name == "HERTSMERE"
replace district_outcome = 1 if district_name == "HERTFORDSHIRE NORTH"
replace district_outcome = 1 if district_name == "HERTFORDSHIRE SOUTH WEST"
replace district_outcome = 1 if district_name == "ST ALBANS"
replace district_outcome = 1 if district_name == "STEVENAGE"
replace district_outcome = 1 if district_name == "WATFORD"
replace district_outcome = 1 if district_name == "WELWYN HATFIELD"
replace district_outcome = 1 if district_name == "HERTFORDSHIRE WEST"
replace district_outcome = 1 if district_name == "ASHFORD"
replace district_outcome = 1 if district_name == "CANTERBURY"
replace district_outcome = 1 if district_name == "DARTFORD"
replace district_outcome = 1 if district_name == "DOVER"
replace district_outcome = 1 if district_name == "FAVERSHAM"
replace district_outcome = 1 if district_name == "FOLKESTONE & HYTHE"
replace district_outcome = 1 if district_name == "GILLINGHAM"
replace district_outcome = 1 if district_name == "GRAVESHAM"
replace district_outcome = 1 if district_name == "MAIDSTONE"
replace district_outcome = 1 if district_name == "MEDWAY"
replace district_outcome = 1 if district_name == "KENT MID"
replace district_outcome = 1 if district_name == "THANET NORTH"
replace district_outcome = 1 if district_name == "SEVENOAKS"
replace district_outcome = 1 if district_name == "THANET SOUTH"
replace district_outcome = 1 if district_name == "TONBRIDGE & MALLING"
replace district_outcome = 1 if district_name == "TUNBRIDGE WELLS"
replace district_outcome = 1 if district_name == "BANBURY"
replace district_outcome = 1 if district_name == "HENLEY"
replace district_outcome = 2 if district_name == "OXFORD EAST"
replace district_outcome = 1 if district_name == "OXFORD WEST & ABINGDON"
replace district_outcome = 1 if district_name == "WANTAGE"
replace district_outcome = 1 if district_name == "WITNEY"
replace district_outcome = 1 if district_name == "CHERTSY & WALTON"
replace district_outcome = 1 if district_name == "SURREY EAST"
replace district_outcome = 1 if district_name == "EPSOM & EWELL"
replace district_outcome = 1 if district_name == "ESHER"
replace district_outcome = 1 if district_name == "GUILDFORD"
replace district_outcome = 1 if district_name == "MOLE VALLEY"
replace district_outcome = 1 if district_name == "SURREY NORTH WEST"
replace district_outcome = 1 if district_name == "REIGATE"
replace district_outcome = 1 if district_name == "SURREY SOUTH WEST"
replace district_outcome = 1 if district_name == "SPELTHORNE"
replace district_outcome = 1 if district_name == "WOKING"
replace district_outcome = 1 if district_name == "ARUNDEL"
replace district_outcome = 1 if district_name == "CHICHESTER"
replace district_outcome = 1 if district_name == "CRAWLEY"
replace district_outcome = 1 if district_name == "HORSHAM"
replace district_outcome = 1 if district_name == "SUSSEX MID"
replace district_outcome = 1 if district_name == "SHOREHAM"
replace district_outcome = 1 if district_name == "WORTHING"
replace district_outcome = 1 if district_name == "CAMBRIDGE"
replace district_outcome = 1 if district_name == "HUNTINGDON"
replace district_outcome = 1 if district_name == "CAMBRIDGESHIRE NORTH EAST"
replace district_outcome = 1 if district_name == "PETERBOROUGH"
replace district_outcome = 1 if district_name == "CAMBRIDGESHIRE SOUTH EAST"
replace district_outcome = 1 if district_name == "CAMBRIDGESHIRE SOUTH WEST"
replace district_outcome = 1 if district_name == "GREAT YARMOUTH"
replace district_outcome = 1 if district_name == "NORFOLK MID"
replace district_outcome = 1 if district_name == "NORFOLK NORTH"
replace district_outcome = 1 if district_name == "NORFOLK NORTH WEST"
replace district_outcome = 1 if district_name == "NORWICH NORTH"
replace district_outcome = 2 if district_name == "NORWICH SOUTH"
replace district_outcome = 1 if district_name == "NORFOLK SOUTH"
replace district_outcome = 1 if district_name == "NORFOLK SOUTH WEST"
replace district_outcome = 1 if district_name == "BURY ST. EDMUNDS"
replace district_outcome = 1 if district_name == "SUFFOLK CENTRAL"
replace district_outcome = 1 if district_name == "IPSWICH"
replace district_outcome = 1 if district_name == "SUFFOLK SOUTH"
replace district_outcome = 1 if district_name == "SUFFOLK COASTAL"
replace district_outcome = 1 if district_name == "WAVENEY"
replace district_outcome = 2 if district_name == "BARKING"
replace district_outcome = 1 if district_name == "BATTERSEA"
replace district_outcome = 1 if district_name == "BECKENHAM"
replace district_outcome = 2 if district_name == "BETHNAL GREEN & STEPNEY"
replace district_outcome = 1 if district_name == "BEXLEYHEATH"
replace district_outcome = 2 if district_name == "BOW & POPLAR"
replace district_outcome = 2 if district_name == "BRENT EAST"
replace district_outcome = 1 if district_name == "BRENT NORTH"
replace district_outcome = 2 if district_name == "BRENT SOUTH"
replace district_outcome = 1 if district_name == "BRENTFORD & ISLEWORTH"
replace district_outcome = 1 if district_name == "CARSHALTON & WALLINGTON"
replace district_outcome = 1 if district_name == "CHELSEA"
replace district_outcome = 1 if district_name == "CHINGFORD"
replace district_outcome = 1 if district_name == "CHIPPING BARNET"
replace district_outcome = 1 if district_name == "CHISLEHURST"
replace district_outcome = 1 if district_name == "CROYDON CENTRAL"
replace district_outcome = 1 if district_name == "CROYDON NORTH EAST"
replace district_outcome = 1 if district_name == "CROYDON NORTH WEST"
replace district_outcome = 1 if district_name == "CROYDON SOUTH"
replace district_outcome = 2 if district_name == "DAGENHAM"
replace district_outcome = 1 if district_name == "DULWICH"
replace district_outcome = 1 if district_name == "EALING NORTH"
replace district_outcome = 1 if district_name == "EALING ACTON"
replace district_outcome = 2 if district_name == "EALING SOUTHALL"
replace district_outcome = 1 if district_name == "EDMONTON"
replace district_outcome = 1 if district_name == "ELTHAM"
replace district_outcome = 1 if district_name == "ENFIELD NORTH"
replace district_outcome = 1 if district_name == "ENFIELD SOUTHGATE"
replace district_outcome = 1 if district_name == "ERITH & CRAYFORD"
replace district_outcome = 1 if district_name == "FELTHAM & HESTON"
replace district_outcome = 1 if district_name == "FINCHLEY"
replace district_outcome = 1 if district_name == "FULHAM"
replace district_outcome = 3 if district_name == "GREENWICH"
replace district_outcome = 2 if district_name == "HACKNEY NORTH & STOKE NEWINGTON"
replace district_outcome = 2 if district_name == "HACKNEY SOUTH & SHOREDITCH"
replace district_outcome = 2 if district_name == "HAMMERSMITH"
replace district_outcome = 1 if district_name == "HAMPSTEAD & HIGHGATE"
replace district_outcome = 1 if district_name == "HARROW EAST"
replace district_outcome = 1 if district_name == "HARROW WEST"
replace district_outcome = 1 if district_name == "HAYES & HARLINGTON"
replace district_outcome = 1 if district_name == "HENDON NORTH"
replace district_outcome = 1 if district_name == "HENDON SOUTH"
replace district_outcome = 2 if district_name == "HOLBORN & ST PANCRAS"
replace district_outcome = 1 if district_name == "HORNCHURCH"
replace district_outcome = 1 if district_name == "HORNSEY & WOOD GREEN"
replace district_outcome = 1 if district_name == "ILFORD NORTH"
replace district_outcome = 1 if district_name == "ILFORD SOUTH"
replace district_outcome = 2 if district_name == "ISLINGTON NORTH"
replace district_outcome = 2 if district_name == "ISLINGTON SOUTH & FINSBURY"
replace district_outcome = 1 if district_name == "KENSINGTON"
replace district_outcome = 1 if district_name == "KINGSTON UPON THAMES"
replace district_outcome = 1 if district_name == "LEWISHAM EAST"
replace district_outcome = 1 if district_name == "LEWISHAM WEST"
replace district_outcome = 2 if district_name == "LEWISHAM DEPTFORD"
replace district_outcome = 2 if district_name == "LEYTON"
replace district_outcome = 1 if district_name == "MITCHAM & MORDEN"
replace district_outcome = 2 if district_name == "NEWHAM NORTH EAST"
replace district_outcome = 2 if district_name == "NEWHAM NORTH WEST"
replace district_outcome = 2 if district_name == "NEWHAM SOUTH"
replace district_outcome = 2 if district_name == "NORWOOD"
replace district_outcome = 1 if district_name == "OLD BEXLEY & SIDCUP"
replace district_outcome = 1 if district_name == "ORPINGTON"
replace district_outcome = 2 if district_name == "PECKHAM"
replace district_outcome = 1 if district_name == "PUTNEY"
replace district_outcome = 1 if district_name == "RAVENSBOURNE"
replace district_outcome = 1 if district_name == "RICHMOND & BARNES"
replace district_outcome = 1 if district_name == "ROMFORD"
replace district_outcome = 1 if district_name == "RUISLIP - NORTHWOOD"
replace district_outcome = 3 if district_name == "SOUTHWARK & BERMONDSEY"
replace district_outcome = 1 if district_name == "STREATHAM"
replace district_outcome = 1 if district_name == "SURBITON"
replace district_outcome = 1 if district_name == "SUTTON & CHEAM"
replace district_outcome = 1 if district_name == "CITY OF LONDON & WESTMINSTER SOUTH"
replace district_outcome = 2 if district_name == "TOOTING"
replace district_outcome = 2 if district_name == "TOTTENHAM"
replace district_outcome = 1 if district_name == "TWICKENHAM"
replace district_outcome = 1 if district_name == "UPMINSTER"
replace district_outcome = 1 if district_name == "UXBRIDGE"
replace district_outcome = 2 if district_name == "VAUXHALL"
replace district_outcome = 1 if district_name == "WALTHAMSTOW"
replace district_outcome = 1 if district_name == "WANSTEAD & WOODFORD"
replace district_outcome = 1 if district_name == "WESTMINSTER NORTH"
replace district_outcome = 1 if district_name == "WIMBLEDON"
replace district_outcome = 3 if district_name == "WOOLWICH"
replace district_outcome = 1 if district_name == "BATH"
replace district_outcome = 1 if district_name == "BRISTOL EAST"
replace district_outcome = 1 if district_name == "BRISTOL NORTH WEST"
replace district_outcome = 2 if district_name == "BRISTOL SOUTH"
replace district_outcome = 1 if district_name == "BRISTOL WEST"
replace district_outcome = 1 if district_name == "KINGSWOOD"
replace district_outcome = 1 if district_name == "NORTHAVON"
replace district_outcome = 1 if district_name == "WANSDYKE"
replace district_outcome = 1 if district_name == "WESTON-SUPER-MARE"
replace district_outcome = 1 if district_name == "WOODSPRING"
replace district_outcome = 1 if district_name == "FALMOUTH & CAMBORNE"
replace district_outcome = 1 if district_name == "CORNWALL NORTH"
replace district_outcome = 1 if district_name == "CORNWALL SOUTH EAST"
replace district_outcome = 1 if district_name == "ST IVES"
replace district_outcome = 3 if district_name == "TRURO"
replace district_outcome = 1 if district_name == "EXETER"
replace district_outcome = 1 if district_name == "HONITON"
replace district_outcome = 1 if district_name == "DEVON NORTH"
replace district_outcome = 3 if district_name == "PLYMOUTH DEVONPORT"
replace district_outcome = 1 if district_name == "PLYMOUTH DRAKE"
replace district_outcome = 1 if district_name == "PLYMOUTH SUTTON"
replace district_outcome = 1 if district_name == "SOUTH HAMS"
replace district_outcome = 1 if district_name == "TEIGNBRIDGE"
replace district_outcome = 1 if district_name == "TIVERTON"
replace district_outcome = 1 if district_name == "TORBAY"
replace district_outcome = 1 if district_name == "DEVON WEST & TORRIDGE"
replace district_outcome = 1 if district_name == "BOURNEMOUTH EAST"
replace district_outcome = 1 if district_name == "BOURNEMOUTH WEST"
replace district_outcome = 1 if district_name == "CHRISTCHURCH"
replace district_outcome = 1 if district_name == "DORSET NORTH"
replace district_outcome = 1 if district_name == "POOLE"
replace district_outcome = 1 if district_name == "DORSET SOUTH"
replace district_outcome = 1 if district_name == "DORSET WEST"
replace district_outcome = 1 if district_name == "CHELTENHAM"
replace district_outcome = 1 if district_name == "CIRENCESTER & TEWKESBURY"
replace district_outcome = 1 if district_name == "GLOUCESTER"
replace district_outcome = 1 if district_name == "STROUD"
replace district_outcome = 1 if district_name == "GLOUCESTERSHIRE WEST"
replace district_outcome = 1 if district_name == "BRIDGWATER"
replace district_outcome = 1 if district_name == "SOMERTON & FROME"
replace district_outcome = 1 if district_name == "TAUNTON"
replace district_outcome = 1 if district_name == "WELLS"
replace district_outcome = 3 if district_name == "YEOVIL"
replace district_outcome = 1 if district_name == "DEVIZES"
replace district_outcome = 1 if district_name == "WILTSHIRE NORTH"
replace district_outcome = 1 if district_name == "SALISBURY"
replace district_outcome = 1 if district_name == "SWINDON"
replace district_outcome = 1 if district_name == "WESTBURY"
replace district_outcome = 1 if district_name == "BROMSGROVE"
replace district_outcome = 1 if district_name == "HEREFORD"
replace district_outcome = 1 if district_name == "LEOMINSTER"
replace district_outcome = 1 if district_name == "WORCESTERSHIRE MID"
replace district_outcome = 1 if district_name == "WORCESTERSHIRE SOUTH"
replace district_outcome = 1 if district_name == "WORCESTER"
replace district_outcome = 1 if district_name == "WYRE FOREST"
replace district_outcome = 1 if district_name == "LUDLOW"
replace district_outcome = 1 if district_name == "SHROPSHIRE NORTH"
replace district_outcome = 1 if district_name == "SHREWSBURY & ATCHAM"
replace district_outcome = 2 if district_name == "WREKIN THE"
replace district_outcome = 1 if district_name == "BURTON"
replace district_outcome = 1 if district_name == "CANNOCK & BURNTWOOD"
replace district_outcome = 1 if district_name == "STAFFORDSHIRE MID"
replace district_outcome = 2 if district_name == "NEWCASTLE UNDER LYME"
replace district_outcome = 1 if district_name == "STAFFORDSHIRE SOUTH EAST"
replace district_outcome = 1 if district_name == "STAFFORDSHIRE SOUTH"
replace district_outcome = 1 if district_name == "STAFFORD"
replace district_outcome = 1 if district_name == "STAFFORDSHIRE MOORLANDS"
replace district_outcome = 2 if district_name == "STOKE-ON-TRENT CENTRAL"
replace district_outcome = 2 if district_name == "STOKE-ON-TRENT NORTH"
replace district_outcome = 2 if district_name == "STOKE-ON-TRENT SOUTH"
replace district_outcome = 1 if district_name == "WARWICKSHIRE NORTH"
replace district_outcome = 1 if district_name == "NUNEATON"
replace district_outcome = 1 if district_name == "RUGBY & KENILWORTH"
replace district_outcome = 1 if district_name == "STRATFORD-ON-AVON"
replace district_outcome = 1 if district_name == "WARWICK & LEAMINGTON"
replace district_outcome = 1 if district_name == "ALDRIDGE-BROWNHILLS"
replace district_outcome = 1 if district_name == "BIRMINGHAM EDGBASTON"
replace district_outcome = 2 if district_name == "BIRMINGHAM ERDINGTON"
replace district_outcome = 1 if district_name == "BIRMINGHAM HALL GREEN"
replace district_outcome = 2 if district_name == "BIRMINGHAM HODGE HILL"
replace district_outcome = 2 if district_name == "BIRMINGHAM LADYWOOD"
replace district_outcome = 1 if district_name == "BIRMINGHAM NORTHFIELD"
replace district_outcome = 2 if district_name == "BIRMINGHAM PERRY BARR"
replace district_outcome = 2 if district_name == "BIRMINGHAM SMALL HEATH"
replace district_outcome = 2 if district_name == "BIRMINGHAM SPARKBROOK"
replace district_outcome = 1 if district_name == "BIRMINGHAM YARDLEY"
replace district_outcome = 1 if district_name == "BIRMINGHAM SELLY OAK"
replace district_outcome = 2 if district_name == "COVENTRY NORTH EAST"
replace district_outcome = 2 if district_name == "COVENTRY NORTH WEST"
replace district_outcome = 2 if district_name == "COVENTRY SOUTH EAST"
replace district_outcome = 1 if district_name == "COVENTRY SOUTH WEST"
replace district_outcome = 2 if district_name == "DUDLEY EAST"
replace district_outcome = 1 if district_name == "DUDLEY WEST"
replace district_outcome = 1 if district_name == "HALESOWEN & STOURBRIDGE"
replace district_outcome = 1 if district_name == "MERIDEN"
replace district_outcome = 1 if district_name == "SOLIHULL"
replace district_outcome = 1 if district_name == "SUTTON COLDFIELD"
replace district_outcome = 2 if district_name == "WALSALL NORTH"
replace district_outcome = 2 if district_name == "WALSALL SOUTH"
replace district_outcome = 2 if district_name == "WARLEY EAST"
replace district_outcome = 2 if district_name == "WARLEY WEST"
replace district_outcome = 2 if district_name == "WEST BROMWICH EAST"
replace district_outcome = 2 if district_name == "WEST BROMWICH WEST"
replace district_outcome = 1 if district_name == "WOLVERHAMPTON NORTH EAST"
replace district_outcome = 2 if district_name == "WOLVERHAMPTON SOUTH EAST"
replace district_outcome = 1 if district_name == "WOLVERHAMPTON SOUTH WEST"
replace district_outcome = 1 if district_name == "AMBER VALLEY"
replace district_outcome = 2 if district_name == "BOLSOVER"
replace district_outcome = 2 if district_name == "CHESTERFIELD"
replace district_outcome = 1 if district_name == "EREWASH"
replace district_outcome = 1 if district_name == "DERBY NORTH"
replace district_outcome = 2 if district_name == "DERBY SOUTH"
replace district_outcome = 1 if district_name == "HIGH PEAK"
replace district_outcome = 2 if district_name == "DERBYSHIRE NORTH EAST"
replace district_outcome = 1 if district_name == "DERBYSHIRE SOUTH"
replace district_outcome = 1 if district_name == "DERBYSHIRE WEST"
replace district_outcome = 1 if district_name == "BLABY"
replace district_outcome = 1 if district_name == "BOSWORTH"
replace district_outcome = 1 if district_name == "HARBOROUGH"
replace district_outcome = 2 if district_name == "LEICESTER EAST"
replace district_outcome = 2 if district_name == "LEICESTER SOUTH"
replace district_outcome = 2 if district_name == "LEICESTER WEST"
replace district_outcome = 1 if district_name == "LOUGHBOROUGH"
replace district_outcome = 1 if district_name == "LEICESTERSHIRE NORTH WEST"
replace district_outcome = 1 if district_name == "RUTLAND & MELTON"
replace district_outcome = 1 if district_name == "LINDSEY EAST"
replace district_outcome = 1 if district_name == "GAINSBOROUGH & HORNCASTLE"
replace district_outcome = 1 if district_name == "GRANTHAM"
replace district_outcome = 1 if district_name == "HOLLAND WITH BOSTON"
replace district_outcome = 1 if district_name == "LINCOLN"
replace district_outcome = 1 if district_name == "STAMFORD & SPALDING"
replace district_outcome = 1 if district_name == "CORBY"
replace district_outcome = 1 if district_name == "DAVENTRY"
replace district_outcome = 1 if district_name == "KETTERING"
replace district_outcome = 1 if district_name == "NORTHAMPTON NORTH"
replace district_outcome = 1 if district_name == "NORTHAMPTON SOUTH"
replace district_outcome = 1 if district_name == "WELLINGBOROUGH"
replace district_outcome = 2 if district_name == "ASHFIELD"
replace district_outcome = 2 if district_name == "BASSETLAW"
replace district_outcome = 1 if district_name == "BROXTOWE"
replace district_outcome = 1 if district_name == "GEDLING"
replace district_outcome = 2 if district_name == "MANSFIELD"
replace district_outcome = 1 if district_name == "NEWARK"
replace district_outcome = 1 if district_name == "NOTTINGHAM EAST"
replace district_outcome = 2 if district_name == "NOTTINGHAM NORTH"
replace district_outcome = 1 if district_name == "NOTTINGHAM SOUTH"
replace district_outcome = 1 if district_name == "RUSHCLIFFE"
replace district_outcome = 1 if district_name == "SHERWOOD"
replace district_outcome = 1 if district_name == "BEVERLEY"
replace district_outcome = 1 if district_name == "BOOTHFERRY"
replace district_outcome = 1 if district_name == "BRIDLINGTON"
replace district_outcome = 1 if district_name == "BRIGG & CLEETHORPES"
replace district_outcome = 2 if district_name == "GLANFORD & SCUNTHORPE"
replace district_outcome = 2 if district_name == "GREAT GRIMSBY"
replace district_outcome = 2 if district_name == "HULL EAST"
replace district_outcome = 2 if district_name == "HULL NORTH"
replace district_outcome = 2 if district_name == "HULL WEST"
replace district_outcome = 1 if district_name == "HARROGATE"
replace district_outcome = 1 if district_name == "RICHMOND (YORKS)"
replace district_outcome = 1 if district_name == "RYEDALE"
replace district_outcome = 1 if district_name == "SCARBOROUGH"
replace district_outcome = 1 if district_name == "SELBY"
replace district_outcome = 1 if district_name == "SKIPTON & RIPON"
replace district_outcome = 1 if district_name == "YORK"
replace district_outcome = 2 if district_name == "BARNSLEY CENTRAL"
replace district_outcome = 2 if district_name == "BARNSLEY EAST"
replace district_outcome = 2 if district_name == "BARNSLEY WEST & PENISTONE"
replace district_outcome = 2 if district_name == "DON VALLEY"
replace district_outcome = 2 if district_name == "DONCASTER CENTRAL"
replace district_outcome = 2 if district_name == "DONCASTER NORTH"
replace district_outcome = 2 if district_name == "ROTHER VALLEY"
replace district_outcome = 2 if district_name == "ROTHERHAM"
replace district_outcome = 2 if district_name == "SHEFFIELD CENTRAL"
replace district_outcome = 2 if district_name == "SHEFFIELD ATTERCLIFFE"
replace district_outcome = 2 if district_name == "SHEFFIELD BRIGHTSIDE"
replace district_outcome = 1 if district_name == "SHEFFIELD HALLAM"
replace district_outcome = 2 if district_name == "SHEFFIELD HEELEY"
replace district_outcome = 2 if district_name == "SHEFFIELD HILLSBOROUGH"
replace district_outcome = 2 if district_name == "WENTWORTH"
replace district_outcome = 1 if district_name == "BATLEY & SPEN"
replace district_outcome = 2 if district_name == "BRADFORD NORTH"
replace district_outcome = 2 if district_name == "BRADFORD SOUTH"
replace district_outcome = 2 if district_name == "BRADFORD WEST"
replace district_outcome = 1 if district_name == "CALDER VALLEY"
replace district_outcome = 1 if district_name == "COLNE VALLEY"
replace district_outcome = 2 if district_name == "DEWSBURY"
replace district_outcome = 1 if district_name == "ELMET"
replace district_outcome = 2 if district_name == "HALIFAX"
replace district_outcome = 2 if district_name == "HEMSWORTH"
replace district_outcome = 2 if district_name == "HUDDERSFIELD"
replace district_outcome = 1 if district_name == "KEIGHLEY"
replace district_outcome = 2 if district_name == "LEEDS CENTRAL"
replace district_outcome = 2 if district_name == "LEEDS EAST"
replace district_outcome = 1 if district_name == "LEEDS NORTH EAST"
replace district_outcome = 1 if district_name == "LEEDS NORTH WEST"
replace district_outcome = 2 if district_name == "LEEDS WEST"
replace district_outcome = 2 if district_name == "LEEDS SOUTH & MORLEY"
replace district_outcome = 2 if district_name == "NORMANTON"
replace district_outcome = 2 if district_name == "PONTEFRACT & CASTLEFORD"
replace district_outcome = 1 if district_name == "PUDSEY"
replace district_outcome = 1 if district_name == "SHIPLEY"
replace district_outcome = 2 if district_name == "WAKEFIELD"
replace district_outcome = 1 if district_name == "CHESTER CITY OF"
replace district_outcome = 1 if district_name == "CONGLETON"
replace district_outcome = 2 if district_name == "CREWE & NANTWICH"
replace district_outcome = 1 if district_name == "EDDISBURY"
replace district_outcome = 1 if district_name == "ELLESMERE PORT & NESTON"
replace district_outcome = 2 if district_name == "HALTON"
replace district_outcome = 1 if district_name == "MACCLESFIELD"
replace district_outcome = 1 if district_name == "TATTON"
replace district_outcome = 2 if district_name == "WARRINGTON NORTH"
replace district_outcome = 1 if district_name == "WARRINGTON SOUTH"
replace district_outcome = 1 if district_name == "ALTRINCHAM & SALE"
replace district_outcome = 2 if district_name == "ASHTON-UNDER-LYNE"
replace district_outcome = 1 if district_name == "BOLTON NORTH EAST"
replace district_outcome = 2 if district_name == "BOLTON SOUTH EAST"
replace district_outcome = 1 if district_name == "BOLTON WEST"
replace district_outcome = 1 if district_name == "BURY NORTH"
replace district_outcome = 1 if district_name == "BURY SOUTH"
replace district_outcome = 1 if district_name == "CHEADLE"
replace district_outcome = 1 if district_name == "DAVYHULME"
replace district_outcome = 2 if district_name == "DENTON & REDDISH"
replace district_outcome = 2 if district_name == "ECCLES"
replace district_outcome = 1 if district_name == "HAZEL GROVE"
replace district_outcome = 2 if district_name == "HEYWOOD & MIDDLETON"
replace district_outcome = 2 if district_name == "LEIGH"
replace district_outcome = 1 if district_name == "LITTLEBOROUGH & SADDLEWORTH"
replace district_outcome = 2 if district_name == "MAKERFIELD"
replace district_outcome = 2 if district_name == "MANCHESTER CENTRAL"
replace district_outcome = 2 if district_name == "MANCHESTER BLACKLEY"
replace district_outcome = 2 if district_name == "MANCHESTER GORTON"
replace district_outcome = 2 if district_name == "MANCHESTER WITHINGTON"
replace district_outcome = 2 if district_name == "MANCHESTER WYTHENSHAWE"
replace district_outcome = 2 if district_name == "OLDHAM CENTRAL & ROYTON"
replace district_outcome = 2 if district_name == "OLDHAM WEST"
replace district_outcome = 3 if district_name == "ROCHDALE"
replace district_outcome = 2 if district_name == "SALFORD EAST"
replace district_outcome = 2 if district_name == "STALYBRIDGE & HYDE"
replace district_outcome = 1 if district_name == "STOCKPORT"
replace district_outcome = 2 if district_name == "STRETFORD"
replace district_outcome = 2 if district_name == "WIGAN"
replace district_outcome = 2 if district_name == "WORSLEY"
replace district_outcome = 2 if district_name == "BLACKBURN"
replace district_outcome = 1 if district_name == "BLACKPOOL NORTH"
replace district_outcome = 1 if district_name == "BLACKPOOL SOUTH"
replace district_outcome = 2 if district_name == "BURNLEY"
replace district_outcome = 1 if district_name == "CHORLEY"
replace district_outcome = 1 if district_name == "FYLDE"
replace district_outcome = 1 if district_name == "HYNDBURN"
replace district_outcome = 1 if district_name == "LANCASTER"
replace district_outcome = 1 if district_name == "MORECOMBE & LUNESDALE"
replace district_outcome = 1 if district_name == "PENDLE"
replace district_outcome = 2 if district_name == "PRESTON"
replace district_outcome = 1 if district_name == "RIBBLE VALLEY"
replace district_outcome = 1 if district_name == "ROSSENDALE & DARWEN"
replace district_outcome = 1 if district_name == "SOUTH RIBBLE"
replace district_outcome = 1 if district_name == "LANCASHIRE WEST"
replace district_outcome = 1 if district_name == "WYRE"
replace district_outcome = 2 if district_name == "BIRKENHEAD"
replace district_outcome = 2 if district_name == "BOOTLE"
replace district_outcome = 1 if district_name == "CROSBY"
replace district_outcome = 2 if district_name == "KNOWSLEY NORTH"
replace district_outcome = 2 if district_name == "KNOWSLEY SOUTH"
replace district_outcome = 2 if district_name == "LIVERPOOL BROADGREEN"
replace district_outcome = 2 if district_name == "LIVERPOOL GARSTON"
replace district_outcome = 3 if district_name == "LIVERPOOL MOSSLEY HILL"
replace district_outcome = 2 if district_name == "LIVERPOOL RIVERSIDE"
replace district_outcome = 2 if district_name == "LIVERPOOL WALTON"
replace district_outcome = 2 if district_name == "LIVERPOOL WEST DERBY"
replace district_outcome = 3 if district_name == "SOUTHPORT"
replace district_outcome = 2 if district_name == "ST HELENS NORTH"
replace district_outcome = 2 if district_name == "ST HELENS SOUTH"
replace district_outcome = 1 if district_name == "WALLASEY"
replace district_outcome = 1 if district_name == "WIRRAL SOUTH"
replace district_outcome = 1 if district_name == "WIRRAL WEST"
replace district_outcome = 1 if district_name == "BARROW & FURNESS"
replace district_outcome = 2 if district_name == "CARLISLE"
replace district_outcome = 2 if district_name == "COPELAND"
replace district_outcome = 1 if district_name == "PENRITH & THE BORDER"
replace district_outcome = 1 if district_name == "WESTMORLAND & LONSDALE"
replace district_outcome = 2 if district_name == "WORKINGTON"
replace district_outcome = 2 if district_name == "HARTLEPOOL"
replace district_outcome = 1 if district_name == "LANGBAURGH"
replace district_outcome = 2 if district_name == "MIDDLESBROUGH"
replace district_outcome = 2 if district_name == "REDCAR"
replace district_outcome = 2 if district_name == "STOCKTON NORTH"
replace district_outcome = 1 if district_name == "STOCKTON SOUTH"
replace district_outcome = 2 if district_name == "BISHOP AUCKLAND"
replace district_outcome = 2 if district_name == "DURHAM CITY OF"
replace district_outcome = 1 if district_name == "DARLINGTON"
replace district_outcome = 2 if district_name == "EASINGTON"
replace district_outcome = 2 if district_name == "DURHAM NORTH"
replace district_outcome = 2 if district_name == "DURHAM NORTH WEST"
replace district_outcome = 2 if district_name == "SEDGEFIELD"
replace district_outcome = 3 if district_name == "BERWICK-UPON-TWEED"
replace district_outcome = 2 if district_name == "BLYTH VALLEY"
replace district_outcome = 1 if district_name == "HEXHAM"
replace district_outcome = 2 if district_name == "WANSBECK"
replace district_outcome = 2 if district_name == "BLAYDON"
replace district_outcome = 2 if district_name == "GATESHEAD EAST"
replace district_outcome = 2 if district_name == "HOUGHTON & WASHINGTON"
replace district_outcome = 2 if district_name == "JARROW"
replace district_outcome = 2 if district_name == "NEWCASTLE UPON TYNE CENTRAL"
replace district_outcome = 2 if district_name == "NEWCASTLE UPON TYNE EAST"
replace district_outcome = 2 if district_name == "NEWCASTLE UPON TYNE NORTH"
replace district_outcome = 2 if district_name == "SOUTH SHIELDS"
replace district_outcome = 2 if district_name == "SUNDERLAND NORTH"
replace district_outcome = 2 if district_name == "SUNDERLAND SOUTH"
replace district_outcome = 2 if district_name == "TYNE BRIDGE"
replace district_outcome = 1 if district_name == "TYNEMOUTH"
replace district_outcome = 2 if district_name == "WALLSEND"
replace district_outcome = 2 if district_name == "ALYN & DEESIDE"
replace district_outcome = 1 if district_name == "CLWYD NORTH WEST"
replace district_outcome = 2 if district_name == "CLWYD SOUTH WEST"
replace district_outcome = 1 if district_name == "DELYN"
replace district_outcome = 2 if district_name == "WREXHAM"
replace district_outcome = 2 if district_name == "CARMARTHEN"
replace district_outcome = 3 if district_name == "CEREDIGION & PEMBROKE NORTH"
replace district_outcome = 2 if district_name == "LLANELLI"
replace district_outcome = 1 if district_name == "PEMBROKE"
replace district_outcome = 2 if district_name == "BLAENAU GWENT"
replace district_outcome = 2 if district_name == "ISLWYN"
replace district_outcome = 1 if district_name == "MONMOUTH"
replace district_outcome = 2 if district_name == "NEWPORT EAST"
replace district_outcome = 2 if district_name == "NEWPORT WEST"
replace district_outcome = 2 if district_name == "TORFAEN"
replace district_outcome = 4 if district_name == "CAERNARFON"
replace district_outcome = 1 if district_name == "CONWY"
replace district_outcome = 4 if district_name == "MEIRIONNYDD NANT CONWY"
replace district_outcome = 4 if district_name == "YNYS MON"
replace district_outcome = 2 if district_name == "BRIDGEND"
replace district_outcome = 2 if district_name == "CAERPHILLY"
replace district_outcome = 2 if district_name == "CYNON VALLEY"
replace district_outcome = 2 if district_name == "MERTHYR TYDFIL & RHYMNEY"
replace district_outcome = 2 if district_name == "OGMORE"
replace district_outcome = 2 if district_name == "PONTYPRIDD"
replace district_outcome = 2 if district_name == "RHONDDA"
replace district_outcome = 3 if district_name == "BRECON & RADNOR"
replace district_outcome = 3 if district_name == "MONTGOMERY"
replace district_outcome = 1 if district_name == "CARDIFF CENTRAL"
replace district_outcome = 1 if district_name == "CARDIFF NORTH"
replace district_outcome = 2 if district_name == "CARDIFF SOUTH & PENARTH"
replace district_outcome = 2 if district_name == "CARDIFF WEST"
replace district_outcome = 1 if district_name == "VALE OF GLAMORGAN"
replace district_outcome = 2 if district_name == "ABERAVON"
replace district_outcome = 2 if district_name == "GOWER"
replace district_outcome = 2 if district_name == "NEATH"
replace district_outcome = 2 if district_name == "SWANSEA EAST"
replace district_outcome = 2 if district_name == "SWANSEA WEST"
replace district_outcome = 3 if district_name == "ROXBURGH & BERWICKSHIRE"
replace district_outcome = 3 if district_name == "TWEEDDALE ETTRICK & LAUDERDALE"
replace district_outcome = 2 if district_name == "CLACKMANNAN"
replace district_outcome = 2 if district_name == "FALKIRK EAST"
replace district_outcome = 2 if district_name == "FALKIRK WEST"
replace district_outcome = 1 if district_name == "STIRLING"
replace district_outcome = 1 if district_name == "DUMFRIES"
replace district_outcome = 1 if district_name == "GALLOWAY & UPPER NITHSDALE"
replace district_outcome = 2 if district_name == "FIFE CENTRAL"
replace district_outcome = 2 if district_name == "DUNFERMLINE EAST"
replace district_outcome = 2 if district_name == "DUNFERMLINE WEST"
replace district_outcome = 2 if district_name == "KIRKCALDY"
replace district_outcome = 3 if district_name == "FIFE NORTH EAST"
replace district_outcome = 2 if district_name == "ABERDEEN NORTH"
replace district_outcome = 2 if district_name == "ABERDEEN SOUTH"
replace district_outcome = 4 if district_name == "BANFF & BUCHAN"
replace district_outcome = 3 if district_name == "GORDON"
replace district_outcome = 1 if district_name == "KINCARDINE & DEESIDE"
replace district_outcome = 4 if district_name == "MORAY"
replace district_outcome = 3 if district_name == "CAITHNESS & SUTHERLAND"
replace district_outcome = 3 if district_name == "INVERNESS NAIRN & LOCHABER"
replace district_outcome = 3 if district_name == "ROSS CROMARTY AND SKYE"
replace district_outcome = 2 if district_name == "EAST LOTHIAN"
replace district_outcome = 2 if district_name == "EDINBURGH CENTRAL"
replace district_outcome = 2 if district_name == "EDINBURGH EAST"
replace district_outcome = 2 if district_name == "EDINBURGH LEITH"
replace district_outcome = 1 if district_name == "EDINBURGH PENTLANDS"
replace district_outcome = 2 if district_name == "EDINBURGH SOUTH"
replace district_outcome = 1 if district_name == "EDINBURGH WEST"
replace district_outcome = 2 if district_name == "LINLITHGOW"
replace district_outcome = 2 if district_name == "LIVINGSTON"
replace district_outcome = 2 if district_name == "MIDLOTHIAN"
replace district_outcome = 3 if district_name == "ARGYLL & BUTE"
replace district_outcome = 1 if district_name == "AYR"
replace district_outcome = 2 if district_name == "CARRICK, CUMNOCK & DOON VALLEY"
replace district_outcome = 2 if district_name == "CLYDEBANK & MILNGAVIE"
replace district_outcome = 2 if district_name == "CLYDESDALE"
replace district_outcome = 2 if district_name == "CUMBERNAULD & KILSYTH"
replace district_outcome = 2 if district_name == "CUNNINGHAME NORTH"
replace district_outcome = 2 if district_name == "CUNNINGHAME SOUTH"
replace district_outcome = 2 if district_name == "DUMBARTON"
replace district_outcome = 2 if district_name == "EAST KILBRIDE"
replace district_outcome = 1 if district_name == "EASTWOOD"
replace district_outcome = 2 if district_name == "GLASGOW CATHCART"
replace district_outcome = 2 if district_name == "GLASGOW CENTRAL"
replace district_outcome = 2 if district_name == "GLASGOW GARSCADDEN"
replace district_outcome = 2 if district_name == "GLASGOW GOVAN"
replace district_outcome = 2 if district_name == "GLASGOW HILLHEAD"
replace district_outcome = 2 if district_name == "GLASGOW MARYHILL"
replace district_outcome = 2 if district_name == "GLASGOW POLLOK"
replace district_outcome = 2 if district_name == "GLASGOW PROVAN"
replace district_outcome = 2 if district_name == "GLASGOW RUTHERGLEN"
replace district_outcome = 2 if district_name == "GLASGOW SHETTLESTON"
replace district_outcome = 2 if district_name == "GLASGOW SPRINGBURN"
replace district_outcome = 2 if district_name == "GREENOCK & PORT GLASGOW"
replace district_outcome = 2 if district_name == "HAMILTON"
replace district_outcome = 2 if district_name == "KILMARNOCK & LOUDOUN"
replace district_outcome = 2 if district_name == "MONKLANDS EAST"
replace district_outcome = 2 if district_name == "MONKLANDS WEST"
replace district_outcome = 2 if district_name == "MOTHERWELL NORTH"
replace district_outcome = 2 if district_name == "MOTHERWELL SOUTH"
replace district_outcome = 2 if district_name == "PAISLEY NORTH"
replace district_outcome = 2 if district_name == "PAISLEY SOUTH"
replace district_outcome = 2 if district_name == "RENFREW WEST & INVERCLYDE"
replace district_outcome = 2 if district_name == "STRATHKELVIN & BEARSDEN"
replace district_outcome = 4 if district_name == "ANGUS EAST"
replace district_outcome = 2 if district_name == "DUNDEE EAST"
replace district_outcome = 2 if district_name == "DUNDEE WEST"
replace district_outcome = 1 if district_name == "TAYSIDE NORTH"
replace district_outcome = 1 if district_name == "PERTH & KINROSS"
replace district_outcome = 3 if district_name == "ORKNEY & SHETLAND"
replace district_outcome = 2 if district_name == "WESTERN ISLES"
replace district_outcome = 9 if district_name == "BELFAST EAST"
replace district_outcome = 9 if district_name == "BELFAST NORTH"
replace district_outcome = 9 if district_name == "BELFAST SOUTH"
replace district_outcome = 9 if district_name == "BELFAST WEST"
replace district_outcome = 9 if district_name == "ANTRIM EAST"
replace district_outcome = 9 if district_name == "LONDONDERRY EAST"
replace district_outcome = 9 if district_name == "FERMANAGH AND SOUTH TYRONE"
replace district_outcome = 9 if district_name == "FOYLE"
replace district_outcome = 9 if district_name == "LAGAN VALLEY"
replace district_outcome = 9 if district_name == "MID-ULSTER"
replace district_outcome = 9 if district_name == "NEWRY AND ARMAGH"
replace district_outcome = 9 if district_name == "ANTRIM  NORTH"
replace district_outcome = 9 if district_name == "DOWN NORTH"
replace district_outcome = 9 if district_name == "ANTRIM SOUTH"
replace district_outcome = 9 if district_name == "DOWN SOUTH"
replace district_outcome = 9 if district_name == "STRANGFORD"
replace district_outcome = 9 if district_name == "UPPER BANN"


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by district

gen margin = .

replace margin = 9.550929 if district_name == "LUTON SOUTH"
replace margin = 36.02327 if district_name == "BEDFORDSHIRE MID"
replace margin = 29.07858 if district_name == "BEDFORDSHIRE NORTH"
replace margin = 27.04256 if district_name == "LUTON NORTH"
replace margin = 35.88956 if district_name == "BEDFORDSHIRE SOUTH WEST"
replace margin = 34.89028 if district_name == "BERKSHIRE EAST"
replace margin = 28.40771 if district_name == "NEWBURY"
replace margin = 30.61197 if district_name == "READING EAST"
replace margin = 32.94462 if district_name == "READING WEST"
replace margin = 7.338692 if district_name == "SLOUGH"
replace margin = 29.83657 if district_name == "WINDSOR & MAIDENHEAD"
replace margin = 31.43668 if district_name == "WOKINGHAM"
replace margin = 28.88796 if district_name == "AYLESBURY"
replace margin = 42.24541 if district_name == "BEACONSFIELD"
replace margin = 33.77514 if district_name == "BUCKINGHAM"
replace margin = 35.02829 if district_name == "CHESHAM & AMERSHAM"
replace margin = 18.51186 if district_name == "MILTON KEYNES"
replace margin = 26.38624 if district_name == "WYCOMBE"
replace margin = 40.61238 if district_name == "BEXHILL & BATTLE"
replace margin = 20.63188 if district_name == "BRIGHTON KEMPTOWN"
replace margin = 21.05045 if district_name == "BRIGHTON PAVILION"
replace margin = 30.19484 if district_name == "EASTBOURNE"
replace margin = 14.06394 if district_name == "HASTINGS & RYE"
replace margin = 37.01491 if district_name == "HOVE"
replace margin = 24.16822 if district_name == "LEWES"
replace margin = 36.72322 if district_name == "WEALDEN"
replace margin = 5.276262 if district_name == "BASILDON"
replace margin = 29.27504 if district_name == "BILLERICAY"
replace margin = 27.69663 if district_name == "BRAINTREE"
replace margin = 35.48375 if district_name == "BRENTWOOD & ONGAR"
replace margin = 38.85659 if district_name == "CASTLE POINT"
replace margin = 11.44201 if district_name == "CHELMSFORD"
replace margin = 41.5686 if district_name == "EPPING FOREST"
replace margin = 10.67148 if district_name == "HARLOW"
replace margin = 21.31353 if district_name == "HARWICH"
replace margin = 21.74843 if district_name == "COLCHESTER NORTH"
replace margin = 33.17834 if district_name == "ROCHFORD"
replace margin = 28.71672 if district_name == "SAFFRON WALDEN"
replace margin = 24.36963 if district_name == "COLCHESTER SOUTH & MALDON"
replace margin = 33.81028 if district_name == "SOUTHEND EAST"
replace margin = 16.3091 if district_name == "SOUTHEND WEST"
replace margin = 1.427567 if district_name == "THURROCK"
replace margin = 29.72869 if district_name == "ALDERSHOT"
replace margin = 29.79535 if district_name == "BASINGSTOKE"
replace margin = 35.58488 if district_name == "HAMPSHIRE EAST"
replace margin = 19.24019 if district_name == "EASTLEIGH"
replace margin = 31.2116 if district_name == "FAREHAM"
replace margin = 26.94059 if district_name == "GOSPORT"
replace margin = 28.99187 if district_name == "HAVANT"
replace margin = 8.202817 if district_name == "ISLE OF WIGHT"
replace margin = 37.79478 if district_name == "NEW FOREST"
replace margin = 24.66274 if district_name == "HAMPSHIRE NORTH WEST"
replace margin = 30.56188 if district_name == "PORTSMOUTH NORTH"
replace margin = .3770808 if district_name == "PORTSMOUTH SOUTH"
replace margin = 24.41684 if district_name == "ROMSEY & WATERSIDE"
replace margin = 12.18256 if district_name == "SOUTHAMPTON ITCHEN"
replace margin = 12.32105 if district_name == "SOUTHAMPTON TEST"
replace margin = 12.16018 if district_name == "WINCHESTER"
replace margin = 43.28633 if district_name == "BROXBOURNE"
replace margin = 29.2023 if district_name == "HERTFORD & STORTFORD"
replace margin = 32.75029 if district_name == "HERTSMERE"
replace margin = 17.92293 if district_name == "HERTFORDSHIRE NORTH"
replace margin = 26.85998 if district_name == "HERTFORDSHIRE SOUTH WEST"
replace margin = 18.01759 if district_name == "ST ALBANS"
replace margin = 9.540655 if district_name == "STEVENAGE"
replace margin = 20.48525 if district_name == "WATFORD"
replace margin = 18.31667 if district_name == "WELWYN HATFIELD"
replace margin = 23.35049 if district_name == "HERTFORDSHIRE WEST"
replace margin = 29.21107 if district_name == "ASHFORD"
replace margin = 26.47148 if district_name == "CANTERBURY"
replace margin = 26.02186 if district_name == "DARTFORD"
replace margin = 11.87395 if district_name == "DOVER"
replace margin = 22.99543 if district_name == "FAVERSHAM"
replace margin = 18.09852 if district_name == "FOLKESTONE & HYTHE"
replace margin = 23.19465 if district_name == "GILLINGHAM"
replace margin = 15.23374 if district_name == "GRAVESHAM"
replace margin = 18.67791 if district_name == "MAIDSTONE"
replace margin = 21.21445 if district_name == "MEDWAY"
replace margin = 28.35093 if district_name == "KENT MID"
replace margin = 34.7094 if district_name == "THANET NORTH"
replace margin = 31.01531 if district_name == "SEVENOAKS"
replace margin = 29.57847 if district_name == "THANET SOUTH"
replace margin = 27.50867 if district_name == "TONBRIDGE & MALLING"
replace margin = 28.45645 if district_name == "TUNBRIDGE WELLS"
replace margin = 32.7655 if district_name == "BANBURY"
replace margin = 34.82782 if district_name == "HENLEY"
replace margin = 2.624982 if district_name == "OXFORD EAST"
replace margin = 8.988889 if district_name == "OXFORD WEST & ABINGDON"
replace margin = 23.46673 if district_name == "WANTAGE"
replace margin = 31.73326 if district_name == "WITNEY"
replace margin = 32.37758 if district_name == "CHERTSY & WALTON"
replace margin = 39.44808 if district_name == "SURREY EAST"
replace margin = 38.96584 if district_name == "EPSOM & EWELL"
replace margin = 39.89372 if district_name == "ESHER"
replace margin = 21.50741 if district_name == "GUILDFORD"
replace margin = 30.82764 if district_name == "MOLE VALLEY"
replace margin = 39.13123 if district_name == "SURREY NORTH WEST"
replace margin = 34.83887 if district_name == "REIGATE"
replace margin = 25.06291 if district_name == "SURREY SOUTH WEST"
replace margin = 37.09048 if district_name == "SPELTHORNE"
replace margin = 26.6955 if district_name == "WOKING"
replace margin = 33.70887 if district_name == "ARUNDEL"
replace margin = 33.45104 if district_name == "CHICHESTER"
replace margin = 20.55407 if district_name == "CRAWLEY"
replace margin = 38.27509 if district_name == "HORSHAM"
replace margin = 29.57813 if district_name == "SUSSEX MID"
replace margin = 30.86632 if district_name == "SHOREHAM"
replace margin = 33.01863 if district_name == "WORTHING"
replace margin = 9.352359 if district_name == "CAMBRIDGE"
replace margin = 42.40666 if district_name == "HUNTINGDON"
replace margin = 2.486549 if district_name == "CAMBRIDGESHIRE NORTH EAST"
replace margin = 15.79236 if district_name == "PETERBOROUGH"
replace margin = 31.25692 if district_name == "CAMBRIDGESHIRE SOUTH EAST"
replace margin = 28.77481 if district_name == "CAMBRIDGESHIRE SOUTH WEST"
replace margin = 20.58764 if district_name == "GREAT YARMOUTH"
replace margin = 31.16649 if district_name == "NORFOLK MID"
replace margin = 28.32091 if district_name == "NORFOLK NORTH"
replace margin = 18.61725 if district_name == "NORFOLK NORTH WEST"
replace margin = 15.64902 if district_name == "NORWICH NORTH"
replace margin = .6474987 if district_name == "NORWICH SOUTH"
replace margin = 19.57039 if district_name == "NORFOLK SOUTH"
replace margin = 36.20451 if district_name == "NORFOLK SOUTH WEST"
replace margin = 37.78881 if district_name == "BURY ST. EDMUNDS"
replace margin = 26.98315 if district_name == "SUFFOLK CENTRAL"
replace margin = 1.663115 if district_name == "IPSWICH"
replace margin = 25.54855 if district_name == "SUFFOLK SOUTH"
replace margin = 25.91104 if district_name == "SUFFOLK COASTAL"
replace margin = 18.35473 if district_name == "WAVENEY"
replace margin = 9.869431 if district_name == "BARKING"
replace margin = 1.810232 if district_name == "BATTERSEA"
replace margin = 30.44088 if district_name == "BECKENHAM"
replace margin = 16.45901 if district_name == "BETHNAL GREEN & STEPNEY"
replace margin = 25.26209 if district_name == "BEXLEYHEATH"
replace margin = 13.64266 if district_name == "BOW & POPLAR"
replace margin = 4.200549 if district_name == "BRENT EAST"
replace margin = 35.09399 if district_name == "BRENT NORTH"
replace margin = 19.475 if district_name == "BRENT SOUTH"
replace margin = 14.46473 if district_name == "BRENTFORD & ISLEWORTH"
replace margin = 27.79407 if district_name == "CARSHALTON & WALLINGTON"
replace margin = 46.63515 if district_name == "CHELSEA"
replace margin = 41.22942 if district_name == "CHINGFORD"
replace margin = 34.89534 if district_name == "CHIPPING BARNET"
replace margin = 34.59154 if district_name == "CHISLEHURST"
replace margin = 32.28175 if district_name == "CROYDON CENTRAL"
replace margin = 28.46198 if district_name == "CROYDON NORTH EAST"
replace margin = 10.04408 if district_name == "CROYDON NORTH WEST"
replace margin = 39.73114 if district_name == "CROYDON SOUTH"
replace margin = 5.945529 if district_name == "DAGENHAM"
replace margin = .461042 if district_name == "DULWICH"
replace margin = 28.17957 if district_name == "EALING NORTH"
replace margin = 25.65161 if district_name == "EALING ACTON"
replace margin = 15.28571 if district_name == "EALING SOUTHALL"
replace margin = 15.19785 if district_name == "EDMONTON"
replace margin = 15.53407 if district_name == "ELTHAM"
replace margin = 27.06748 if district_name == "ENFIELD NORTH"
replace margin = 37.93816 if district_name == "ENFIELD SOUTHGATE"
replace margin = 15.64233 if district_name == "ERITH & CRAYFORD"
replace margin = 9.09502 if district_name == "FELTHAM & HESTON"
replace margin = 22.24746 if district_name == "FINCHLEY"
replace margin = 15.04808 if district_name == "FULHAM"
replace margin = 5.737639 if district_name == "GREENWICH"
replace margin = 19.77999 if district_name == "HACKNEY NORTH & STOKE NEWINGTON"
replace margin = 19.14433 if district_name == "HACKNEY SOUTH & SHOREDITCH"
replace margin = 6.87564 if district_name == "HAMMERSMITH"
replace margin = 4.906552 if district_name == "HAMPSTEAD & HIGHGATE"
replace margin = 30.66866 if district_name == "HARROW EAST"
replace margin = 28.01226 if district_name == "HARROW WEST"
replace margin = 13.74867 if district_name == "HAYES & HARLINGTON"
replace margin = 30.16806 if district_name == "HENDON NORTH"
replace margin = 31.94807 if district_name == "HENDON SOUTH"
replace margin = 19.5116 if district_name == "HOLBORN & ST PANCRAS"
replace margin = 22.75658 if district_name == "HORNCHURCH"
replace margin = 3.010305 if district_name == "HORNSEY & WOOD GREEN"
replace margin = 27.54802 if district_name == "ILFORD NORTH"
replace margin = 10.8707 if district_name == "ILFORD SOUTH"
replace margin = 24.64275 if district_name == "ISLINGTON NORTH"
replace margin = 1.95303 if district_name == "ISLINGTON SOUTH & FINSBURY"
replace margin = 14.25732 if district_name == "KENSINGTON"
replace margin = 25.9771 if district_name == "KINGSTON UPON THAMES"
replace margin = 10.92849 if district_name == "LEWISHAM EAST"
replace margin = 8.296492 if district_name == "LEWISHAM WEST"
replace margin = 17.93262 if district_name == "LEWISHAM DEPTFORD"
replace margin = 11.56693 if district_name == "LEYTON"
replace margin = 12.94842 if district_name == "MITCHAM & MORDEN"
replace margin = 21.13095 if district_name == "NEWHAM NORTH EAST"
replace margin = 30.04774 if district_name == "NEWHAM NORTH WEST"
replace margin = 9.309683 if district_name == "NEWHAM SOUTH"
replace margin = 12.46306 if district_name == "NORWOOD"
replace margin = 41.52802 if district_name == "OLD BEXLEY & SIDCUP"
replace margin = 27.19932 if district_name == "ORPINGTON"
replace margin = 28.8008 if district_name == "PECKHAM"
replace margin = 14.4109 if district_name == "PUTNEY"
replace margin = 37.6463 if district_name == "RAVENSBOURNE"
replace margin = 3.878846 if district_name == "RICHMOND & BARNES"
replace margin = 33.18062 if district_name == "ROMFORD"
replace margin = 38.76605 if district_name == "RUISLIP - NORTHWOOD"
replace margin = 7.720517 if district_name == "SOUTHWARK & BERMONDSEY"
replace margin = 5.71897 if district_name == "STREATHAM"
replace margin = 27.39545 if district_name == "SURBITON"
replace margin = 32.14052 if district_name == "SUTTON & CHEAM"
replace margin = 36.00538 if district_name == "CITY OF LONDON & WESTMINSTER SOUTH"
replace margin = 2.970093 if district_name == "TOOTING"
replace margin = 8.237353 if district_name == "TOTTENHAM"
replace margin = 13.52475 if district_name == "TWICKENHAM"
replace margin = 33.64402 if district_name == "UPMINSTER"
replace margin = 33.10461 if district_name == "UXBRIDGE"
replace margin = 21.17981 if district_name == "VAUXHALL"
replace margin = 4.291553 if district_name == "WALTHAMSTOW"
replace margin = 39.12463 if district_name == "WANSTEAD & WOODFORD"
replace margin = 7.855143 if district_name == "WESTMINSTER NORTH"
replace margin = 23.4446 if district_name == "WIMBLEDON"
replace margin = 4.717486 if district_name == "WOOLWICH"
replace margin = 2.725237 if district_name == "BATH"
replace margin = 8.20955 if district_name == "BRISTOL EAST"
replace margin = 12.01957 if district_name == "BRISTOL NORTH WEST"
replace margin = 2.758729 if district_name == "BRISTOL SOUTH"
replace margin = 14.19803 if district_name == "BRISTOL WEST"
replace margin = 7.497994 if district_name == "KINGSWOOD"
replace margin = 22.67239 if district_name == "NORTHAVON"
replace margin = 26.39591 if district_name == "WANSDYKE"
replace margin = 13.85007 if district_name == "WESTON-SUPER-MARE"
replace margin = 29.58519 if district_name == "WOODSPRING"
replace margin = 9.321987 if district_name == "FALMOUTH & CAMBORNE"
replace margin = 9.837088 if district_name == "CORNWALL NORTH"
replace margin = 11.8244 if district_name == "CORNWALL SOUTH EAST"
replace margin = 14.50987 if district_name == "ST IVES"
replace margin = 8.213946 if district_name == "TRURO"
replace margin = 12.62595 if district_name == "EXETER"
replace margin = 28.05454 if district_name == "HONITON"
replace margin = 8.104824 if district_name == "DEVON NORTH"
replace margin = 12.99875 if district_name == "PLYMOUTH DEVONPORT"
replace margin = 7.970109 if district_name == "PLYMOUTH DRAKE"
replace margin = 7.919717 if district_name == "PLYMOUTH SUTTON"
replace margin = 21.27012 if district_name == "SOUTH HAMS"
replace margin = 18.07198 if district_name == "TEIGNBRIDGE"
replace margin = 16.94254 if district_name == "TIVERTON"
replace margin = 16.40137 if district_name == "TORBAY"
replace margin = 11.02663 if district_name == "DEVON WEST & TORRIDGE"
replace margin = 27.67662 if district_name == "BOURNEMOUTH EAST"
replace margin = 23.1699 if district_name == "BOURNEMOUTH WEST"
replace margin = 41.34758 if district_name == "CHRISTCHURCH"
replace margin = 20.6647 if district_name == "DORSET NORTH"
replace margin = 24.92468 if district_name == "POOLE"
replace margin = 27.37513 if district_name == "DORSET SOUTH"
replace margin = 24.54684 if district_name == "DORSET WEST"
replace margin = 7.827713 if district_name == "CHELTENHAM"
replace margin = 19.32923 if district_name == "CIRENCESTER & TEWKESBURY"
replace margin = 20.04697 if district_name == "GLOUCESTER"
replace margin = 18.88275 if district_name == "STROUD"
replace margin = 18.45753 if district_name == "GLOUCESTERSHIRE WEST"
replace margin = 21.22154 if district_name == "BRIDGWATER"
replace margin = 17.46087 if district_name == "SOMERTON & FROME"
replace margin = 17.63207 if district_name == "TAUNTON"
replace margin = 15.97075 if district_name == "WELLS"
replace margin = 10.16387 if district_name == "YEOVIL"
replace margin = 26.85201 if district_name == "DEVIZES"
replace margin = 17.08631 if district_name == "WILTSHIRE NORTH"
replace margin = 19.86356 if district_name == "SALISBURY"
replace margin = 7.246334 if district_name == "SWINDON"
replace margin = 15.20701 if district_name == "WESTBURY"
replace margin = 31.43369 if district_name == "BROMSGROVE"
replace margin = 2.699244 if district_name == "HEREFORD"
replace margin = 25.93848 if district_name == "LEOMINSTER"
replace margin = 24.14698 if district_name == "WORCESTERSHIRE MID"
replace margin = 23.37593 if district_name == "WORCESTERSHIRE SOUTH"
replace margin = 19.74462 if district_name == "WORCESTER"
replace margin = 13.15967 if district_name == "WYRE FOREST"
replace margin = 22.92887 if district_name == "LUDLOW"
replace margin = 24.75911 if district_name == "SHROPSHIRE NORTH"
replace margin = 16.64738 if district_name == "SHREWSBURY & ATCHAM"
replace margin = 2.252371 if district_name == "WREKIN THE"
replace margin = 17.08496 if district_name == "BURTON"
replace margin = 4.944742 if district_name == "CANNOCK & BURNTWOOD"
replace margin = 25.89778 if district_name == "STAFFORDSHIRE MID"
replace margin = 9.61697 if district_name == "NEWCASTLE UNDER LYME"
replace margin = 20.70376 if district_name == "STAFFORDSHIRE SOUTH EAST"
replace margin = 40.78576 if district_name == "STAFFORDSHIRE SOUTH"
replace margin = 23.81672 if district_name == "STAFFORD"
replace margin = 24.14601 if district_name == "STAFFORDSHIRE MOORLANDS"
replace margin = 21.53121 if district_name == "STOKE-ON-TRENT CENTRAL"
replace margin = 15.74441 if district_name == "STOKE-ON-TRENT NORTH"
replace margin = 9.679335 if district_name == "STOKE-ON-TRENT SOUTH"
replace margin = 5.010716 if district_name == "WARWICKSHIRE NORTH"
replace margin = 10.30543 if district_name == "NUNEATON"
replace margin = 26.6409 if district_name == "RUGBY & KENILWORTH"
replace margin = 34.06238 if district_name == "STRATFORD-ON-AVON"
replace margin = 25.27888 if district_name == "WARWICK & LEAMINGTON"
replace margin = 25.01413 if district_name == "ALDRIDGE-BROWNHILLS"
replace margin = 22.99426 if district_name == "BIRMINGHAM EDGBASTON"
replace margin = 6.642971 if district_name == "BIRMINGHAM ERDINGTON"
replace margin = 16.69149 if district_name == "BIRMINGHAM HALL GREEN"
replace margin = 11.73113 if district_name == "BIRMINGHAM HODGE HILL"
replace margin = 26.32297 if district_name == "BIRMINGHAM LADYWOOD"
replace margin = 5.889315 if district_name == "BIRMINGHAM NORTHFIELD"
replace margin = 13.49647 if district_name == "BIRMINGHAM PERRY BARR"
replace margin = 45.16383 if district_name == "BIRMINGHAM SMALL HEATH"
replace margin = 35.16383 if district_name == "BIRMINGHAM SPARKBROOK"
replace margin = 5.994201 if district_name == "BIRMINGHAM YARDLEY"
replace margin = 4.897186 if district_name == "BIRMINGHAM SELLY OAK"
replace margin = 24.92596 if district_name == "COVENTRY NORTH EAST"
replace margin = 14.26736 if district_name == "COVENTRY NORTH WEST"
replace margin = 17.5731 if district_name == "COVENTRY SOUTH EAST"
replace margin = 6.221895 if district_name == "COVENTRY SOUTH WEST"
replace margin = 6.387009 if district_name == "DUDLEY EAST"
replace margin = 15.83773 if district_name == "DUDLEY WEST"
replace margin = 22.2983 if district_name == "HALESOWEN & STOURBRIDGE"
replace margin = 29.02703 if district_name == "MERIDEN"
replace margin = 37.11856 if district_name == "SOLIHULL"
replace margin = 39.32171 if district_name == "SUTTON COLDFIELD"
replace margin = 3.550812 if district_name == "WALSALL NORTH"
replace margin = 2.215033 if district_name == "WALSALL SOUTH"
replace margin = 14.44384 if district_name == "WARLEY EAST"
replace margin = 13.38745 if district_name == "WARLEY WEST"
replace margin = 2.307024 if district_name == "WEST BROMWICH EAST"
replace margin = 13.30749 if district_name == "WEST BROMWICH WEST"
replace margin = .4328178 if district_name == "WOLVERHAMPTON NORTH EAST"
replace margin = 15.84448 if district_name == "WOLVERHAMPTON SOUTH EAST"
replace margin = 19.93123 if district_name == "WOLVERHAMPTON SOUTH WEST"
replace margin = 17.08326 if district_name == "AMBER VALLEY"
replace margin = 27.89301 if district_name == "BOLSOVER"
replace margin = 15.86422 if district_name == "CHESTERFIELD"
replace margin = 16.46578 if district_name == "EREWASH"
replace margin = 11.63625 if district_name == "DERBY NORTH"
replace margin = 3.151898 if district_name == "DERBY SOUTH"
replace margin = 16.90141 if district_name == "HIGH PEAK"
replace margin = 6.671569 if district_name == "DERBYSHIRE NORTH EAST"
replace margin = 15.8504 if district_name == "DERBYSHIRE SOUTH"
replace margin = 17.90428 if district_name == "DERBYSHIRE WEST"
replace margin = 35.57609 if district_name == "BLABY"
replace margin = 27.12967 if district_name == "BOSWORTH"
replace margin = 31.73719 if district_name == "HARBOROUGH"
replace margin = 3.688721 if district_name == "LEICESTER EAST"
replace margin = 3.329431 if district_name == "LEICESTER SOUTH"
replace margin = 2.410727 if district_name == "LEICESTER WEST"
replace margin = 30.23523 if district_name == "LOUGHBOROUGH"
replace margin = 13.37662 if district_name == "LEICESTERSHIRE NORTH WEST"
replace margin = 38.49575 if district_name == "RUTLAND & MELTON"
replace margin = 15.47247 if district_name == "LINDSEY EAST"
replace margin = 18.11458 if district_name == "GAINSBOROUGH & HORNCASTLE"
replace margin = 35.76129 if district_name == "GRANTHAM"
replace margin = 37.14533 if district_name == "HOLLAND WITH BOSTON"
replace margin = 12.84371 if district_name == "LINCOLN"
replace margin = 25.4887 if district_name == "STAMFORD & SPALDING"
replace margin = 3.42856 if district_name == "CORBY"
replace margin = 36.38682 if district_name == "DAVENTRY"
replace margin = 21.79694 if district_name == "KETTERING"
replace margin = 17.90571 if district_name == "NORTHAMPTON NORTH"
replace margin = 31.11814 if district_name == "NORTHAMPTON SOUTH"
replace margin = 25.55719 if district_name == "WELLINGBOROUGH"
replace margin = 8.034182 if district_name == "ASHFIELD"
replace margin = 10.63612 if district_name == "BASSETLAW"
replace margin = 29.29709 if district_name == "BROXTOWE"
replace margin = 30.55479 if district_name == "GEDLING"
replace margin = .1069764 if district_name == "MANSFIELD"
replace margin = 25.83063 if district_name == "NEWARK"
replace margin = .9708945 if district_name == "NOTTINGHAM EAST"
replace margin = 3.293638 if district_name == "NOTTINGHAM NORTH"
replace margin = 4.17375 if district_name == "NOTTINGHAM SOUTH"
replace margin = 35.79908 if district_name == "RUSHCLIFFE"
replace margin = 7.686388 if district_name == "SHERWOOD"
replace margin = 20.91359 if district_name == "BEVERLEY"
replace margin = 33.30407 if district_name == "BOOTHFERRY"
replace margin = 29.34917 if district_name == "BRIDLINGTON"
replace margin = 20.05436 if district_name == "BRIGG & CLEETHORPES"
replace margin = .9010912 if district_name == "GLANFORD & SCUNTHORPE"
replace margin = 17.02359 if district_name == "GREAT GRIMSBY"
replace margin = 30.31347 if district_name == "HULL EAST"
replace margin = 23.84255 if district_name == "HULL NORTH"
replace margin = 21.62637 if district_name == "HULL WEST"
replace margin = 21.21455 if district_name == "HARROGATE"
replace margin = 34.25312 if district_name == "RICHMOND (YORKS)"
replace margin = 14.78042 if district_name == "RYEDALE"
replace margin = 24.94188 if district_name == "SCARBOROUGH"
replace margin = 24.84807 if district_name == "SELBY"
replace margin = 30.5745 if district_name == "SKIPTON & RIPON"
replace margin = .2365322 if district_name == "YORK"
replace margin = 48.65535 if district_name == "BARNSLEY CENTRAL"
replace margin = 60.49091 if district_name == "BARNSLEY EAST"
replace margin = 30.70715 if district_name == "BARNSLEY WEST & PENISTONE"
replace margin = 20.86427 if district_name == "DON VALLEY"
replace margin = 15.96416 if district_name == "DONCASTER CENTRAL"
replace margin = 37.36015 if district_name == "DONCASTER NORTH"
replace margin = 31.46735 if district_name == "ROTHER VALLEY"
replace margin = 37.58862 if district_name == "ROTHERHAM"
replace margin = 50.63749 if district_name == "SHEFFIELD CENTRAL"
replace margin = 35.16261 if district_name == "SHEFFIELD ATTERCLIFFE"
replace margin = 54.16825 if district_name == "SHEFFIELD BRIGHTSIDE"
replace margin = 13.78271 if district_name == "SHEFFIELD HALLAM"
replace margin = 27.13215 if district_name == "SHEFFIELD HEELEY"
replace margin = 5.520277 if district_name == "SHEFFIELD HILLSBOROUGH"
replace margin = 43.34937 if district_name == "WENTWORTH"
replace margin = 2.319364 if district_name == "BATLEY & SPEN"
replace margin = 3.329867 if district_name == "BRADFORD NORTH"
replace margin = .6028092 if district_name == "BRADFORD SOUTH"
replace margin = 15.20662 if district_name == "BRADFORD WEST"
replace margin = 10.15966 if district_name == "CALDER VALLEY"
replace margin = 2.983773 if district_name == "COLNE VALLEY"
replace margin = .7975196 if district_name == "DEWSBURY"
replace margin = 9.788906 if district_name == "ELMET"
replace margin = 2.125272 if district_name == "HALIFAX"
replace margin = 49.77637 if district_name == "HEMSWORTH"
replace margin = 14.50639 if district_name == "HUDDERSFIELD"
replace margin = 10.73104 if district_name == "KEIGHLEY"
replace margin = 30.08394 if district_name == "LEEDS CENTRAL"
replace margin = 22.16999 if district_name == "LEEDS EAST"
replace margin = 17.29422 if district_name == "LEEDS NORTH EAST"
replace margin = 10.07321 if district_name == "LEEDS NORTH WEST"
replace margin = 9.644795 if district_name == "LEEDS WEST"
replace margin = 15.43113 if district_name == "LEEDS SOUTH & MORLEY"
replace margin = 15.49239 if district_name == "NORMANTON"
replace margin = 45.70644 if district_name == "PONTEFRACT & CASTLEFORD"
replace margin = 11.50539 if district_name == "PUDSEY"
replace margin = 23.20497 if district_name == "SHIPLEY"
replace margin = 5.304399 if district_name == "WAKEFIELD"
replace margin = 9.235129 if district_name == "CHESTER CITY OF"
replace margin = 14.52421 if district_name == "CONGLETON"
replace margin = 1.887836 if district_name == "CREWE & NANTWICH"
replace margin = 27.46128 if district_name == "EDDISBURY"
replace margin = 3.205716 if district_name == "ELLESMERE PORT & NESTON"
replace margin = 25.21099 if district_name == "HALTON"
replace margin = 32.42142 if district_name == "MACCLESFIELD"
replace margin = 30.97581 if district_name == "TATTON"
replace margin = 14.0883 if district_name == "WARRINGTON NORTH"
replace margin = 6.10443 if district_name == "WARRINGTON SOUTH"
replace margin = 27.4243 if district_name == "ALTRINCHAM & SALE"
replace margin = 21.46953 if district_name == "ASHTON-UNDER-LYNE"
replace margin = 1.739745 if district_name == "BOLTON NORTH EAST"
replace margin = 23.0562 if district_name == "BOLTON SOUTH EAST"
replace margin = 8.216311 if district_name == "BOLTON WEST"
replace margin = 12.32193 if district_name == "BURY NORTH"
replace margin = 5.166927 if district_name == "BURY SOUTH"
replace margin = 19.19854 if district_name == "CHEADLE"
replace margin = 16.17032 if district_name == "DAVYHULME"
replace margin = 15.71638 if district_name == "DENTON & REDDISH"
replace margin = 19.43025 if district_name == "ECCLES"
replace margin = 3.429509 if district_name == "HAZEL GROVE"
replace margin = 15.59731 if district_name == "HEYWOOD & MIDDLETON"
replace margin = 32.39247 if district_name == "LEIGH"
replace margin = 12.12489 if district_name == "LITTLEBOROUGH & SADDLEWORTH"
replace margin = 28.99366 if district_name == "MAKERFIELD"
replace margin = 49.3725 if district_name == "MANCHESTER CENTRAL"
replace margin = 23.61037 if district_name == "MANCHESTER BLACKLEY"
replace margin = 31.08425 if district_name == "MANCHESTER GORTON"
replace margin = 6.726707 if district_name == "MANCHESTER WITHINGTON"
replace margin = 28.19665 if district_name == "MANCHESTER WYTHENSHAWE"
replace margin = 13.89313 if district_name == "OLDHAM CENTRAL & ROYTON"
replace margin = 14.52072 if district_name == "OLDHAM WEST"
replace margin = 5.420112 if district_name == "ROCHDALE"
replace margin = 31.42857 if district_name == "SALFORD EAST"
replace margin = 11.22498 if district_name == "STALYBRIDGE & HYDE"
replace margin = 6.082507 if district_name == "STOCKPORT"
replace margin = 22.71838 if district_name == "STRETFORD"
replace margin = 37.08228 if district_name == "WIGAN"
replace margin = 12.98952 if district_name == "WORSLEY"
replace margin = 9.80994 if district_name == "BLACKBURN"
replace margin = 16.99752 if district_name == "BLACKPOOL NORTH"
replace margin = 15.02451 if district_name == "BLACKPOOL SOUTH"
replace margin = 14.54276 if district_name == "BURNLEY"
replace margin = 13.34095 if district_name == "CHORLEY"
replace margin = 36.48832 if district_name == "FYLDE"
replace margin = 4.557399 if district_name == "HYNDBURN"
replace margin = 14.24283 if district_name == "LANCASTER"
replace margin = 27.79219 if district_name == "MORECOMBE & LUNESDALE"
replace margin = 5.071002 if district_name == "PENDLE"
replace margin = 23.92726 if district_name == "PRESTON"
replace margin = 39.43059 if district_name == "RIBBLE VALLEY"
replace margin = 8.272038 if district_name == "ROSSENDALE & DARWEN"
replace margin = 14.14857 if district_name == "SOUTH RIBBLE"
replace margin = 2.231973 if district_name == "LANCASHIRE WEST"
replace margin = 29.02536 if district_name == "WYRE"
replace margin = 32.3696 if district_name == "BIRKENHEAD"
replace margin = 46.80741 if district_name == "BOOTLE"
replace margin = 10.24739 if district_name == "CROSBY"
replace margin = 53.72549 if district_name == "KNOWSLEY NORTH"
replace margin = 42.83131 if district_name == "KNOWSLEY SOUTH"
replace margin = 12.62685 if district_name == "LIVERPOOL BROADGREEN"
replace margin = 29.70013 if district_name == "LIVERPOOL GARSTON"
replace margin = 4.859944 if district_name == "LIVERPOOL MOSSLEY HILL"
replace margin = 59.39312 if district_name == "LIVERPOOL RIVERSIDE"
replace margin = 43.21557 if district_name == "LIVERPOOL WALTON"
replace margin = 46.1175 if district_name == "LIVERPOOL WEST DERBY"
replace margin = 3.392225 if district_name == "SOUTHPORT"
replace margin = 26.39861 if district_name == "ST HELENS NORTH"
replace margin = 27.87799 if district_name == "ST HELENS SOUTH"
replace margin = .5198823 if district_name == "WALLASEY"
replace margin = 22.16628 if district_name == "WIRRAL SOUTH"
replace margin = 25.66673 if district_name == "WIRRAL WEST"
replace margin = 7.174699 if district_name == "BARROW & FURNESS"
replace margin = 2.112497 if district_name == "CARLISLE"
replace margin = 4.258572 if district_name == "COPELAND"
replace margin = 31.57168 if district_name == "PENRITH & THE BORDER"
replace margin = 28.38337 if district_name == "WESTMORLAND & LONSDALE"
replace margin = 15.30127 if district_name == "WORKINGTON"
replace margin = 14.53846 if district_name == "HARTLEPOOL"
replace margin = 3.345564 if district_name == "LANGBAURGH"
replace margin = 34.6812 if district_name == "MIDDLESBROUGH"
replace margin = 16.04406 if district_name == "REDCAR"
replace margin = 16.6066 if district_name == "STOCKTON NORTH"
replace margin = 1.301015 if district_name == "STOCKTON SOUTH"
replace margin = 13.16036 if district_name == "BISHOP AUCKLAND"
replace margin = 11.76821 if district_name == "DURHAM CITY OF"
replace margin = 4.993432 if district_name == "DARLINGTON"
replace margin = 51.7626 if district_name == "EASINGTON"
replace margin = 33.65836 if district_name == "DURHAM NORTH"
replace margin = 22.54165 if district_name == "DURHAM NORTH WEST"
replace margin = 28.17321 if district_name == "SEDGEFIELD"
replace margin = 22.60359 if district_name == "BERWICK-UPON-TWEED"
replace margin = 1.8472 if district_name == "BLYTH VALLEY"
replace margin = 17.87955 if district_name == "HEXHAM"
replace margin = 34.36074 if district_name == "WANSBECK"
replace margin = 24.87005 if district_name == "BLAYDON"
replace margin = 35.30834 if district_name == "GATESHEAD EAST"
replace margin = 36.3792 if district_name == "HOUGHTON & WASHINGTON"
replace margin = 40.21439 if district_name == "JARROW"
replace margin = 5.376554 if district_name == "NEWCASTLE UPON TYNE CENTRAL"
replace margin = 29.80164 if district_name == "NEWCASTLE UPON TYNE EAST"
replace margin = 9.982863 if district_name == "NEWCASTLE UPON TYNE NORTH"
replace margin = 32.23037 if district_name == "SOUTH SHIELDS"
replace margin = 27.48595 if district_name == "SUNDERLAND NORTH"
replace margin = 23.65662 if district_name == "SUNDERLAND SOUTH"
replace margin = 42.44018 if district_name == "TYNE BRIDGE"
replace margin = 4.446625 if district_name == "TYNEMOUTH"
replace margin = 33.6867 if district_name == "WALLSEND"
replace margin = 13.5233 if district_name == "ALYN & DEESIDE"
replace margin = 23.70613 if district_name == "CLWYD NORTH WEST"
replace margin = 2.180784 if district_name == "CLWYD SOUTH WEST"
replace margin = 2.332139 if district_name == "DELYN"
replace margin = 8.224551 if district_name == "WREXHAM"
replace margin = 7.982618 if district_name == "CARMARTHEN"
replace margin = 9.730849 if district_name == "CEREDIGION & PEMBROKE NORTH"
replace margin = 41.97157 if district_name == "LLANELLI"
replace margin = 10.02127 if district_name == "PEMBROKE"
replace margin = 64.42297 if district_name == "BLAENAU GWENT"
replace margin = 56.61313 if district_name == "ISLWYN"
replace margin = 19.85138 if district_name == "MONMOUTH"
replace margin = 16.89427 if district_name == "NEWPORT EAST"
replace margin = 5.971861 if district_name == "NEWPORT WEST"
replace margin = 38.77339 if district_name == "TORFAEN"
replace margin = 35.96957 if district_name == "CAERNARFON"
replace margin = 7.436919 if district_name == "CONWY"
replace margin = 11.65101 if district_name == "MEIRIONNYDD NANT CONWY"
replace margin = 10.0007 if district_name == "YNYS MON"
replace margin = 9.50913 if district_name == "BRIDGEND"
replace margin = 39.03109 if district_name == "CAERPHILLY"
replace margin = 56.6763 if district_name == "CYNON VALLEY"
replace margin = 63.45876 if district_name == "MERTHYR TYDFIL & RHYMNEY"
replace margin = 54.3323 if district_name == "OGMORE"
replace margin = 36.8144 if district_name == "PONTYPRIDD"
replace margin = 64.35906 if district_name == "RHONDDA"
replace margin = .1343667 if district_name == "BRECON & RADNOR"
replace margin = 8.09084 if district_name == "MONTGOMERY"
replace margin = 4.83294 if district_name == "CARDIFF CENTRAL"
replace margin = 18.58481 if district_name == "CARDIFF NORTH"
replace margin = 10.2014 if district_name == "CARDIFF SOUTH & PENARTH"
replace margin = 9.059553 if district_name == "CARDIFF WEST"
replace margin = 12.07083 if district_name == "VALE OF GLAMORGAN"
replace margin = 50.7261 if district_name == "ABERAVON"
replace margin = 12.13525 if district_name == "GOWER"
replace margin = 47.22974 if district_name == "NEATH"
replace margin = 44.82303 if district_name == "SWANSEA EAST"
replace margin = 15.51883 if district_name == "SWANSEA WEST"
replace margin = 12.03676 if district_name == "ROXBURGH & BERWICKSHIRE"
replace margin = 20.32426 if district_name == "TWEEDDALE ETTRICK & LAUDERDALE"
replace margin = 32.79473 if district_name == "CLACKMANNAN"
replace margin = 35.57783 if district_name == "FALKIRK EAST"
replace margin = 35.57235 if district_name == "FALKIRK WEST"
replace margin = 2.063786 if district_name == "STIRLING"
replace margin = 16.69526 if district_name == "DUMFRIES"
replace margin = 8.949805 if district_name == "GALLOWAY & UPPER NITHSDALE"
replace margin = 36.76512 if district_name == "FIFE CENTRAL"
replace margin = 49.97704 if district_name == "DUNFERMLINE EAST"
replace margin = 23.9194 if district_name == "DUNFERMLINE WEST"
replace margin = 28.28574 if district_name == "KIRKCALDY"
replace margin = 3.630934 if district_name == "FIFE NORTH EAST"
replace margin = 36.8539 if district_name == "ABERDEEN NORTH"
replace margin = 2.8351 if district_name == "ABERDEEN SOUTH"
replace margin = 5.550881 if district_name == "BANFF & BUCHAN"
replace margin = 17.58707 if district_name == "GORDON"
replace margin = 4.314275 if district_name == "KINCARDINE & DEESIDE"
replace margin = 8.156805 if district_name == "MORAY"
replace margin = 36.91599 if district_name == "CAITHNESS & SUTHERLAND"
replace margin = 11.47839 if district_name == "INVERNESS NAIRN & LOCHABER"
replace margin = 29.72583 if district_name == "ROSS CROMARTY AND SKYE"
replace margin = 19.74867 if district_name == "EAST LOTHIAN"
replace margin = 5.507401 if district_name == "EDINBURGH CENTRAL"
replace margin = 25.64492 if district_name == "EDINBURGH EAST"
replace margin = 26.48414 if district_name == "EDINBURGH LEITH"
replace margin = 8.295125 if district_name == "EDINBURGH PENTLANDS"
replace margin = 3.844245 if district_name == "EDINBURGH SOUTH"
replace margin = 2.498127 if district_name == "EDINBURGH WEST"
replace margin = 22.4587 if district_name == "LINLITHGOW"
replace margin = 26.47578 if district_name == "LIVINGSTON"
replace margin = 26.21579 if district_name == "MIDLOTHIAN"
replace margin = 3.788867 if district_name == "ARGYLL & BUTE"
replace margin = .3426915 if district_name == "AYR"
replace margin = 39.3158 if district_name == "CARRICK, CUMNOCK & DOON VALLEY"
replace margin = 41.1946 if district_name == "CLYDEBANK & MILNGAVIE"
replace margin = 21.79562 if district_name == "CLYDESDALE"
replace margin = 40.39772 if district_name == "CUMBERNAULD & KILSYTH"
replace margin = 10.40871 if district_name == "CUNNINGHAME NORTH"
replace margin = 44.51611 if district_name == "CUNNINGHAME SOUTH"
replace margin = 11.36255 if district_name == "DUMBARTON"
replace margin = 25.25962 if district_name == "EAST KILBRIDE"
replace margin = 12.24847 if district_name == "EASTWOOD"
replace margin = 29.75723 if district_name == "GLASGOW CATHCART"
replace margin = 51.45081 if district_name == "GLASGOW CENTRAL"
replace margin = 55.4073 if district_name == "GLASGOW GARSCADDEN"
replace margin = 52.53959 if district_name == "GLASGOW GOVAN"
replace margin = 7.764695 if district_name == "GLASGOW HILLHEAD"
replace margin = 54.79189 if district_name == "GLASGOW MARYHILL"
replace margin = 48.82704 if district_name == "GLASGOW POLLOK"
replace margin = 60.80021 if district_name == "GLASGOW PROVAN"
replace margin = 31.62212 if district_name == "GLASGOW RUTHERGLEN"
replace margin = 50.2808 if district_name == "GLASGOW SHETTLESTON"
replace margin = 63.42312 if district_name == "GLASGOW SPRINGBURN"
replace margin = 46.03889 if district_name == "GREENOCK & PORT GLASGOW"
replace margin = 45.26212 if district_name == "HAMILTON"
replace margin = 28.90257 if district_name == "KILMARNOCK & LOUDOUN"
replace margin = 44.12644 if district_name == "MONKLANDS EAST"
replace margin = 46.60972 if district_name == "MONKLANDS WEST"
replace margin = 52.96059 if district_name == "MOTHERWELL NORTH"
replace margin = 43.0001 if district_name == "MOTHERWELL SOUTH"
replace margin = 39.69654 if district_name == "PAISLEY NORTH"
replace margin = 41.02238 if district_name == "PAISLEY SOUTH"
replace margin = 8.958094 if district_name == "RENFREW WEST & INVERCLYDE"
replace margin = 4.759871 if district_name == "STRATHKELVIN & BEARSDEN"
replace margin = 3.349895 if district_name == "ANGUS EAST"
replace margin = 2.199636 if district_name == "DUNDEE EAST"
replace margin = 35.38758 if district_name == "DUNDEE WEST"
replace margin = 12.43153 if district_name == "TAYSIDE NORTH"
replace margin = 12.0216 if district_name == "PERTH & KINROSS"
replace margin = 18.39674 if district_name == "ORKNEY & SHETLAND"
replace margin = 14.1844 if district_name == "WESTERN ISLES"
replace margin = 29.77301 if district_name == "BELFAST EAST"
replace margin = 23.25076 if district_name == "BELFAST NORTH"
replace margin = 36.54987 if district_name == "BELFAST SOUTH"
replace margin = 5.421304 if district_name == "BELFAST WEST"
replace margin = 45.90556 if district_name == "ANTRIM EAST"
replace margin = 41.28502 if district_name == "LONDONDERRY EAST"
replace margin = 6.221488 if district_name == "FERMANAGH AND SOUTH TYRONE"
replace margin = 20.27513 if district_name == "FOYLE"
replace margin = 56.20131 if district_name == "LAGAN VALLEY"
replace margin = 17.97373 if district_name == "MID-ULSTER"
replace margin = 10.18788 if district_name == "NEWRY AND ARMAGH"
replace margin = 44.79795 if district_name == "ANTRIM  NORTH"
replace margin = 61.13575 if district_name == "DOWN NORTH"
replace margin = 53.80157 if district_name == "ANTRIM SOUTH"
replace margin = 1.293027 if district_name == "DOWN SOUTH"
replace margin = 55.59415 if district_name == "STRANGFORD"
replace margin = 41.01347 if district_name == "UPPER BANN"

* Effective number of electoral parties by district

gen enep = .

replace enep = 2.64879 if district_name == "LUTON SOUTH"
replace enep = 2.30862 if district_name == "BEDFORDSHIRE MID"
replace enep = 2.594945 if district_name == "BEDFORDSHIRE NORTH"
replace enep = 2.505878 if district_name == "LUTON NORTH"
replace enep = 2.373927 if district_name == "BEDFORDSHIRE SOUTH WEST"
replace enep = 2.23005 if district_name == "BERKSHIRE EAST"
replace enep = 2.13222 if district_name == "NEWBURY"
replace enep = 2.564677 if district_name == "READING EAST"
replace enep = 2.492589 if district_name == "READING WEST"
replace enep = 2.529136 if district_name == "SLOUGH"
replace enep = 2.433079 if district_name == "WINDSOR & MAIDENHEAD"
replace enep = 2.109726 if district_name == "WOKINGHAM"
replace enep = 2.314681 if district_name == "AYLESBURY"
replace enep = 1.991462 if district_name == "BEACONSFIELD"
replace enep = 2.31026 if district_name == "BUCKINGHAM"
replace enep = 2.131866 if district_name == "CHESHAM & AMERSHAM"
replace enep = 2.761296 if district_name == "MILTON KEYNES"
replace enep = 2.497267 if district_name == "WYCOMBE"
replace enep = 1.944885 if district_name == "BEXHILL & BATTLE"
replace enep = 2.419292 if district_name == "BRIGHTON KEMPTOWN"
replace enep = 2.602229 if district_name == "BRIGHTON PAVILION"
replace enep = 2.195364 if district_name == "EASTBOURNE"
replace enep = 2.514493 if district_name == "HASTINGS & RYE"
replace enep = 2.340744 if district_name == "HOVE"
replace enep = 2.286276 if district_name == "LEWES"
replace enep = 2.022168 if district_name == "WEALDEN"
replace enep = 2.709555 if district_name == "BASILDON"
replace enep = 2.468228 if district_name == "BILLERICAY"
replace enep = 2.493093 if district_name == "BRAINTREE"
replace enep = 2.241474 if district_name == "BRENTWOOD & ONGAR"
replace enep = 2.275035 if district_name == "CASTLE POINT"
replace enep = 2.28031 if district_name == "CHELMSFORD"
replace enep = 2.258908 if district_name == "EPPING FOREST"
replace enep = 2.610133 if district_name == "HARLOW"
replace enep = 2.555443 if district_name == "HARWICH"
replace enep = 2.524797 if district_name == "COLCHESTER NORTH"
replace enep = 2.199448 if district_name == "ROCHFORD"
replace enep = 2.323123 if district_name == "SAFFRON WALDEN"
replace enep = 2.40336 if district_name == "COLCHESTER SOUTH & MALDON"
replace enep = 2.344037 if district_name == "SOUTHEND EAST"
replace enep = 2.241178 if district_name == "SOUTHEND WEST"
replace enep = 2.659625 if district_name == "THURROCK"
replace enep = 2.236872 if district_name == "ALDERSHOT"
replace enep = 2.413353 if district_name == "BASINGSTOKE"
replace enep = 1.986207 if district_name == "HAMPSHIRE EAST"
replace enep = 2.542646 if district_name == "EASTLEIGH"
replace enep = 2.125497 if district_name == "FAREHAM"
replace enep = 2.213117 if district_name == "GOSPORT"
replace enep = 2.351386 if district_name == "HAVANT"
replace enep = 2.22388 if district_name == "ISLE OF WIGHT"
replace enep = 2.00937 if district_name == "NEW FOREST"
replace enep = 2.214643 if district_name == "HAMPSHIRE NORTH WEST"
replace enep = 2.457769 if district_name == "PORTSMOUTH NORTH"
replace enep = 2.574616 if district_name == "PORTSMOUTH SOUTH"
replace enep = 2.301833 if district_name == "ROMSEY & WATERSIDE"
replace enep = 2.817004 if district_name == "SOUTHAMPTON ITCHEN"
replace enep = 2.754024 if district_name == "SOUTHAMPTON TEST"
replace enep = 2.273361 if district_name == "WINCHESTER"
replace enep = 2.139178 if district_name == "BROXBOURNE"
replace enep = 2.338617 if district_name == "HERTFORD & STORTFORD"
replace enep = 2.408133 if district_name == "HERTSMERE"
replace enep = 2.613714 if district_name == "HERTFORDSHIRE NORTH"
replace enep = 2.389967 if district_name == "HERTFORDSHIRE SOUTH WEST"
replace enep = 2.448072 if district_name == "ST ALBANS"
replace enep = 2.879581 if district_name == "STEVENAGE"
replace enep = 2.701274 if district_name == "WATFORD"
replace enep = 2.837026 if district_name == "WELWYN HATFIELD"
replace enep = 2.675518 if district_name == "HERTFORDSHIRE WEST"
replace enep = 2.403381 if district_name == "ASHFORD"
replace enep = 2.542881 if district_name == "CANTERBURY"
replace enep = 2.533752 if district_name == "DARTFORD"
replace enep = 2.720349 if district_name == "DOVER"
replace enep = 2.607522 if district_name == "FAVERSHAM"
replace enep = 2.218439 if district_name == "FOLKESTONE & HYTHE"
replace enep = 2.500276 if district_name == "GILLINGHAM"
replace enep = 2.533455 if district_name == "GRAVESHAM"
replace enep = 2.470138 if district_name == "MAIDSTONE"
replace enep = 2.616415 if district_name == "MEDWAY"
replace enep = 2.448562 if district_name == "KENT MID"
replace enep = 2.384765 if district_name == "THANET NORTH"
replace enep = 2.261085 if district_name == "SEVENOAKS"
replace enep = 2.498574 if district_name == "THANET SOUTH"
replace enep = 2.339321 if district_name == "TONBRIDGE & MALLING"
replace enep = 2.247858 if district_name == "TUNBRIDGE WELLS"
replace enep = 2.426546 if district_name == "BANBURY"
replace enep = 2.180784 if district_name == "HENLEY"
replace enep = 2.684882 if district_name == "OXFORD EAST"
replace enep = 2.649232 if district_name == "OXFORD WEST & ABINGDON"
replace enep = 2.449148 if district_name == "WANTAGE"
replace enep = 2.352689 if district_name == "WITNEY"
replace enep = 2.24292 if district_name == "CHERTSY & WALTON"
replace enep = 2.125653 if district_name == "SURREY EAST"
replace enep = 2.163634 if district_name == "EPSOM & EWELL"
replace enep = 1.98676 if district_name == "ESHER"
replace enep = 2.304401 if district_name == "GUILDFORD"
replace enep = 2.138842 if district_name == "MOLE VALLEY"
replace enep = 2.068934 if district_name == "SURREY NORTH WEST"
replace enep = 2.3144 if district_name == "REIGATE"
replace enep = 2.105517 if district_name == "SURREY SOUTH WEST"
replace enep = 2.263479 if district_name == "SPELTHORNE"
replace enep = 2.237935 if district_name == "WOKING"
replace enep = 2.151588 if district_name == "ARUNDEL"
replace enep = 2.133051 if district_name == "CHICHESTER"
replace enep = 2.662427 if district_name == "CRAWLEY"
replace enep = 2.091559 if district_name == "HORSHAM"
replace enep = 2.092051 if district_name == "SUSSEX MID"
replace enep = 2.133153 if district_name == "SHOREHAM"
replace enep = 2.117591 if district_name == "WORTHING"
replace enep = 2.99618 if district_name == "CAMBRIDGE"
replace enep = 2.135775 if district_name == "HUNTINGDON"
replace enep = 2.347291 if district_name == "CAMBRIDGESHIRE NORTH EAST"
replace enep = 2.607413 if district_name == "PETERBOROUGH"
replace enep = 2.27395 if district_name == "CAMBRIDGESHIRE SOUTH EAST"
replace enep = 2.299115 if district_name == "CAMBRIDGESHIRE SOUTH WEST"
replace enep = 2.538498 if district_name == "GREAT YARMOUTH"
replace enep = 2.391217 if district_name == "NORFOLK MID"
replace enep = 2.58597 if district_name == "NORFOLK NORTH"
replace enep = 2.576011 if district_name == "NORFOLK NORTH WEST"
replace enep = 2.788118 if district_name == "NORWICH NORTH"
replace enep = 2.90575 if district_name == "NORWICH SOUTH"
replace enep = 2.401214 if district_name == "NORFOLK SOUTH"
replace enep = 2.371063 if district_name == "NORFOLK SOUTH WEST"
replace enep = 2.334934 if district_name == "BURY ST. EDMUNDS"
replace enep = 2.511705 if district_name == "SUFFOLK CENTRAL"
replace enep = 2.529237 if district_name == "IPSWICH"
replace enep = 2.511433 if district_name == "SUFFOLK SOUTH"
replace enep = 2.408169 if district_name == "SUFFOLK COASTAL"
replace enep = 2.695811 if district_name == "WAVENEY"
replace enep = 2.77665 if district_name == "BARKING"
replace enep = 2.56315 if district_name == "BATTERSEA"
replace enep = 2.405582 if district_name == "BECKENHAM"
replace enep = 2.695968 if district_name == "BETHNAL GREEN & STEPNEY"
replace enep = 2.490014 if district_name == "BEXLEYHEATH"
replace enep = 2.757066 if district_name == "BOW & POPLAR"
replace enep = 2.838544 if district_name == "BRENT EAST"
replace enep = 2.254701 if district_name == "BRENT NORTH"
replace enep = 2.505135 if district_name == "BRENT SOUTH"
replace enep = 2.710154 if district_name == "BRENTFORD & ISLEWORTH"
replace enep = 2.542158 if district_name == "CARSHALTON & WALLINGTON"
replace enep = 2.112285 if district_name == "CHELSEA"
replace enep = 2.19659 if district_name == "CHINGFORD"
replace enep = 2.353754 if district_name == "CHIPPING BARNET"
replace enep = 2.366908 if district_name == "CHISLEHURST"
replace enep = 2.402944 if district_name == "CROYDON CENTRAL"
replace enep = 2.457394 if district_name == "CROYDON NORTH EAST"
replace enep = 2.60885 if district_name == "CROYDON NORTH WEST"
replace enep = 2.086495 if district_name == "CROYDON SOUTH"
replace enep = 2.668211 if district_name == "DAGENHAM"
replace enep = 2.650903 if district_name == "DULWICH"
replace enep = 2.417345 if district_name == "EALING NORTH"
replace enep = 2.513099 if district_name == "EALING ACTON"
replace enep = 2.494215 if district_name == "EALING SOUTHALL"
replace enep = 2.448576 if district_name == "EDMONTON"
replace enep = 2.70309 if district_name == "ELTHAM"
replace enep = 2.430485 if district_name == "ENFIELD NORTH"
replace enep = 2.350718 if district_name == "ENFIELD SOUTHGATE"
replace enep = 2.814419 if district_name == "ERITH & CRAYFORD"
replace enep = 2.618323 if district_name == "FELTHAM & HESTON"
replace enep = 2.435951 if district_name == "FINCHLEY"
replace enep = 2.416152 if district_name == "FULHAM"
replace enep = 2.934368 if district_name == "GREENWICH"
replace enep = 2.786116 if district_name == "HACKNEY NORTH & STOKE NEWINGTON"
replace enep = 2.764719 if district_name == "HACKNEY SOUTH & SHOREDITCH"
replace enep = 2.697394 if district_name == "HAMMERSMITH"
replace enep = 2.783737 if district_name == "HAMPSTEAD & HIGHGATE"
replace enep = 2.50739 if district_name == "HARROW EAST"
replace enep = 2.438859 if district_name == "HARROW WEST"
replace enep = 2.554095 if district_name == "HAYES & HARLINGTON"
replace enep = 2.439231 if district_name == "HENDON NORTH"
replace enep = 2.452609 if district_name == "HENDON SOUTH"
replace enep = 2.603957 if district_name == "HOLBORN & ST PANCRAS"
replace enep = 2.60327 if district_name == "HORNCHURCH"
replace enep = 2.720281 if district_name == "HORNSEY & WOOD GREEN"
replace enep = 2.450645 if district_name == "ILFORD NORTH"
replace enep = 2.533185 if district_name == "ILFORD SOUTH"
replace enep = 2.760966 if district_name == "ISLINGTON NORTH"
replace enep = 2.872204 if district_name == "ISLINGTON SOUTH & FINSBURY"
replace enep = 2.729335 if district_name == "KENSINGTON"
replace enep = 2.355791 if district_name == "KINGSTON UPON THAMES"
replace enep = 2.752939 if district_name == "LEWISHAM EAST"
replace enep = 2.616736 if district_name == "LEWISHAM WEST"
replace enep = 2.658813 if district_name == "LEWISHAM DEPTFORD"
replace enep = 2.918344 if district_name == "LEYTON"
replace enep = 2.606325 if district_name == "MITCHAM & MORDEN"
replace enep = 2.53897 if district_name == "NEWHAM NORTH EAST"
replace enep = 2.484476 if district_name == "NEWHAM NORTH WEST"
replace enep = 2.80793 if district_name == "NEWHAM SOUTH"
replace enep = 2.591211 if district_name == "NORWOOD"
replace enep = 2.181798 if district_name == "OLD BEXLEY & SIDCUP"
replace enep = 2.237139 if district_name == "ORPINGTON"
replace enep = 2.527197 if district_name == "PECKHAM"
replace enep = 2.49719 if district_name == "PUTNEY"
replace enep = 2.112895 if district_name == "RAVENSBOURNE"
replace enep = 2.351665 if district_name == "RICHMOND & BARNES"
replace enep = 2.457739 if district_name == "ROMFORD"
replace enep = 2.139323 if district_name == "RUISLIP - NORTHWOOD"
replace enep = 2.509942 if district_name == "SOUTHWARK & BERMONDSEY"
replace enep = 2.625238 if district_name == "STREATHAM"
replace enep = 2.41642 if district_name == "SURBITON"
replace enep = 2.163325 if district_name == "SUTTON & CHEAM"
replace enep = 2.362592 if district_name == "CITY OF LONDON & WESTMINSTER SOUTH"
replace enep = 2.607668 if district_name == "TOOTING"
replace enep = 2.872207 if district_name == "TOTTENHAM"
replace enep = 2.362822 if district_name == "TWICKENHAM"
replace enep = 2.445679 if district_name == "UPMINSTER"
replace enep = 2.430814 if district_name == "UXBRIDGE"
replace enep = 2.705098 if district_name == "VAUXHALL"
replace enep = 2.974998 if district_name == "WALTHAMSTOW"
replace enep = 2.212707 if district_name == "WANSTEAD & WOODFORD"
replace enep = 2.53438 if district_name == "WESTMINSTER NORTH"
replace enep = 2.622272 if district_name == "WIMBLEDON"
replace enep = 2.806096 if district_name == "WOOLWICH"
replace enep = 2.503489 if district_name == "BATH"
replace enep = 2.798796 if district_name == "BRISTOL EAST"
replace enep = 2.687055 if district_name == "BRISTOL NORTH WEST"
replace enep = 2.851628 if district_name == "BRISTOL SOUTH"
replace enep = 2.861621 if district_name == "BRISTOL WEST"
replace enep = 2.683047 if district_name == "KINGSWOOD"
replace enep = 2.406392 if district_name == "NORTHAVON"
replace enep = 2.608467 if district_name == "WANSDYKE"
replace enep = 2.595485 if district_name == "WESTON-SUPER-MARE"
replace enep = 2.414994 if district_name == "WOODSPRING"
replace enep = 2.811678 if district_name == "FALMOUTH & CAMBORNE"
replace enep = 2.238786 if district_name == "CORNWALL NORTH"
replace enep = 2.317323 if district_name == "CORNWALL SOUTH EAST"
replace enep = 2.63164 if district_name == "ST IVES"
replace enep = 2.396804 if district_name == "TRURO"
replace enep = 2.866369 if district_name == "EXETER"
replace enep = 2.201553 if district_name == "HONITON"
replace enep = 2.240453 if district_name == "DEVON NORTH"
replace enep = 2.89567 if district_name == "PLYMOUTH DEVONPORT"
replace enep = 2.941346 if district_name == "PLYMOUTH DRAKE"
replace enep = 2.635181 if district_name == "PLYMOUTH SUTTON"
replace enep = 2.325465 if district_name == "SOUTH HAMS"
replace enep = 2.387011 if district_name == "TEIGNBRIDGE"
replace enep = 2.22075 if district_name == "TIVERTON"
replace enep = 2.274045 if district_name == "TORBAY"
replace enep = 2.414049 if district_name == "DEVON WEST & TORRIDGE"
replace enep = 2.243014 if district_name == "BOURNEMOUTH EAST"
replace enep = 2.36356 if district_name == "BOURNEMOUTH WEST"
replace enep = 1.985788 if district_name == "CHRISTCHURCH"
replace enep = 2.166088 if district_name == "DORSET NORTH"
replace enep = 2.239465 if district_name == "POOLE"
replace enep = 2.463253 if district_name == "DORSET SOUTH"
replace enep = 2.321635 if district_name == "DORSET WEST"
replace enep = 2.291593 if district_name == "CHELTENHAM"
replace enep = 2.256481 if district_name == "CIRENCESTER & TEWKESBURY"
replace enep = 2.649491 if district_name == "GLOUCESTER"
replace enep = 2.604004 if district_name == "STROUD"
replace enep = 2.789602 if district_name == "GLOUCESTERSHIRE WEST"
replace enep = 2.562366 if district_name == "BRIDGWATER"
replace enep = 2.324158 if district_name == "SOMERTON & FROME"
replace enep = 2.499927 if district_name == "TAUNTON"
replace enep = 2.298705 if district_name == "WELLS"
replace enep = 2.272274 if district_name == "YEOVIL"
replace enep = 2.451294 if district_name == "DEVIZES"
replace enep = 2.204276 if district_name == "WILTSHIRE NORTH"
replace enep = 2.311056 if district_name == "SALISBURY"
replace enep = 2.744291 if district_name == "SWINDON"
replace enep = 2.421165 if district_name == "WESTBURY"
replace enep = 2.486959 if district_name == "BROMSGROVE"
replace enep = 2.31345 if district_name == "HEREFORD"
replace enep = 2.253384 if district_name == "LEOMINSTER"
replace enep = 2.594801 if district_name == "WORCESTERSHIRE MID"
replace enep = 2.381438 if district_name == "WORCESTERSHIRE SOUTH"
replace enep = 2.720061 if district_name == "WORCESTER"
replace enep = 2.678663 if district_name == "WYRE FOREST"
replace enep = 2.443321 if district_name == "LUDLOW"
replace enep = 2.569712 if district_name == "SHROPSHIRE NORTH"
replace enep = 2.739409 if district_name == "SHREWSBURY & ATCHAM"
replace enep = 2.662839 if district_name == "WREKIN THE"
replace enep = 2.535174 if district_name == "BURTON"
replace enep = 2.633999 if district_name == "CANNOCK & BURNTWOOD"
replace enep = 2.693092 if district_name == "STAFFORDSHIRE MID"
replace enep = 2.965777 if district_name == "NEWCASTLE UNDER LYME"
replace enep = 2.741407 if district_name == "STAFFORDSHIRE SOUTH EAST"
replace enep = 2.236692 if district_name == "STAFFORDSHIRE SOUTH"
replace enep = 2.604641 if district_name == "STAFFORD"
replace enep = 2.523565 if district_name == "STAFFORDSHIRE MOORLANDS"
replace enep = 2.504406 if district_name == "STOKE-ON-TRENT CENTRAL"
replace enep = 2.728734 if district_name == "STOKE-ON-TRENT NORTH"
replace enep = 2.563108 if district_name == "STOKE-ON-TRENT SOUTH"
replace enep = 2.591647 if district_name == "WARWICKSHIRE NORTH"
replace enep = 2.791967 if district_name == "NUNEATON"
replace enep = 2.608641 if district_name == "RUGBY & KENILWORTH"
replace enep = 2.120215 if district_name == "STRATFORD-ON-AVON"
replace enep = 2.750143 if district_name == "WARWICK & LEAMINGTON"
replace enep = 2.510165 if district_name == "ALDRIDGE-BROWNHILLS"
replace enep = 2.739695 if district_name == "BIRMINGHAM EDGBASTON"
replace enep = 2.586929 if district_name == "BIRMINGHAM ERDINGTON"
replace enep = 2.830458 if district_name == "BIRMINGHAM HALL GREEN"
replace enep = 2.537225 if district_name == "BIRMINGHAM HODGE HILL"
replace enep = 2.273855 if district_name == "BIRMINGHAM LADYWOOD"
replace enep = 2.617182 if district_name == "BIRMINGHAM NORTHFIELD"
replace enep = 2.460508 if district_name == "BIRMINGHAM PERRY BARR"
replace enep = 2.017081 if district_name == "BIRMINGHAM SMALL HEATH"
replace enep = 2.227058 if district_name == "BIRMINGHAM SPARKBROOK"
replace enep = 2.786694 if district_name == "BIRMINGHAM YARDLEY"
replace enep = 2.679844 if district_name == "BIRMINGHAM SELLY OAK"
replace enep = 2.467228 if district_name == "COVENTRY NORTH EAST"
replace enep = 2.582497 if district_name == "COVENTRY NORTH WEST"
replace enep = 2.773983 if district_name == "COVENTRY SOUTH EAST"
replace enep = 2.753833 if district_name == "COVENTRY SOUTH WEST"
replace enep = 2.57902 if district_name == "DUDLEY EAST"
replace enep = 2.564641 if district_name == "DUDLEY WEST"
replace enep = 2.650618 if district_name == "HALESOWEN & STOURBRIDGE"
replace enep = 2.456229 if district_name == "MERIDEN"
replace enep = 2.208672 if district_name == "SOLIHULL"
replace enep = 2.069279 if district_name == "SUTTON COLDFIELD"
replace enep = 2.722339 if district_name == "WALSALL NORTH"
replace enep = 2.503817 if district_name == "WALSALL SOUTH"
replace enep = 2.499424 if district_name == "WARLEY EAST"
replace enep = 2.545019 if district_name == "WARLEY WEST"
replace enep = 2.678558 if district_name == "WEST BROMWICH EAST"
replace enep = 2.44977 if district_name == "WEST BROMWICH WEST"
replace enep = 2.648921 if district_name == "WOLVERHAMPTON NORTH EAST"
replace enep = 2.622807 if district_name == "WOLVERHAMPTON SOUTH EAST"
replace enep = 2.59157 if district_name == "WOLVERHAMPTON SOUTH WEST"
replace enep = 2.482857 if district_name == "AMBER VALLEY"
replace enep = 2.380677 if district_name == "BOLSOVER"
replace enep = 2.805892 if district_name == "CHESTERFIELD"
replace enep = 2.656994 if district_name == "EREWASH"
replace enep = 2.529838 if district_name == "DERBY NORTH"
replace enep = 2.632621 if district_name == "DERBY SOUTH"
replace enep = 2.803567 if district_name == "HIGH PEAK"
replace enep = 2.693584 if district_name == "DERBYSHIRE NORTH EAST"
replace enep = 2.613745 if district_name == "DERBYSHIRE SOUTH"
replace enep = 2.383181 if district_name == "DERBYSHIRE WEST"
replace enep = 2.223449 if district_name == "BLABY"
replace enep = 2.49602 if district_name == "BOSWORTH"
replace enep = 2.240547 if district_name == "HARBOROUGH"
replace enep = 2.461146 if district_name == "LEICESTER EAST"
replace enep = 2.624392 if district_name == "LEICESTER SOUTH"
replace enep = 2.545578 if district_name == "LEICESTER WEST"
replace enep = 2.512029 if district_name == "LOUGHBOROUGH"
replace enep = 2.676263 if district_name == "LEICESTERSHIRE NORTH WEST"
replace enep = 2.171298 if district_name == "RUTLAND & MELTON"
replace enep = 2.385758 if district_name == "LINDSEY EAST"
replace enep = 2.372775 if district_name == "GAINSBOROUGH & HORNCASTLE"
replace enep = 2.421663 if district_name == "GRANTHAM"
replace enep = 2.380092 if district_name == "HOLLAND WITH BOSTON"
replace enep = 2.721818 if district_name == "LINCOLN"
replace enep = 2.321874 if district_name == "STAMFORD & SPALDING"
replace enep = 2.595364 if district_name == "CORBY"
replace enep = 2.357322 if district_name == "DAVENTRY"
replace enep = 2.597172 if district_name == "KETTERING"
replace enep = 2.747399 if district_name == "NORTHAMPTON NORTH"
replace enep = 2.467222 if district_name == "NORTHAMPTON SOUTH"
replace enep = 2.548455 if district_name == "WELLINGBOROUGH"
replace enep = 2.876282 if district_name == "ASHFIELD"
replace enep = 2.547246 if district_name == "BASSETLAW"
replace enep = 2.530564 if district_name == "BROXTOWE"
replace enep = 2.49554 if district_name == "GEDLING"
replace enep = 3.031118 if district_name == "MANSFIELD"
replace enep = 2.508934 if district_name == "NEWARK"
replace enep = 2.618874 if district_name == "NOTTINGHAM EAST"
replace enep = 2.56932 if district_name == "NOTTINGHAM NORTH"
replace enep = 2.592179 if district_name == "NOTTINGHAM SOUTH"
replace enep = 2.347878 if district_name == "RUSHCLIFFE"
replace enep = 2.621391 if district_name == "SHERWOOD"
replace enep = 2.512509 if district_name == "BEVERLEY"
replace enep = 2.449439 if district_name == "BOOTHFERRY"
replace enep = 2.511287 if district_name == "BRIDLINGTON"
replace enep = 2.700231 if district_name == "BRIGG & CLEETHORPES"
replace enep = 2.565085 if district_name == "GLANFORD & SCUNTHORPE"
replace enep = 2.811238 if district_name == "GREAT GRIMSBY"
replace enep = 2.403926 if district_name == "HULL EAST"
replace enep = 2.612056 if district_name == "HULL NORTH"
replace enep = 2.543293 if district_name == "HULL WEST"
replace enep = 2.289654 if district_name == "HARROGATE"
replace enep = 2.166251 if district_name == "RICHMOND (YORKS)"
replace enep = 2.274078 if district_name == "RYEDALE"
replace enep = 2.641717 if district_name == "SCARBOROUGH"
replace enep = 2.599754 if district_name == "SELBY"
replace enep = 2.266795 if district_name == "SKIPTON & RIPON"
replace enep = 2.700323 if district_name == "YORK"
replace enep = 1.994611 if district_name == "BARNSLEY CENTRAL"
replace enep = 1.701873 if district_name == "BARNSLEY EAST"
replace enep = 2.350836 if district_name == "BARNSLEY WEST & PENISTONE"
replace enep = 2.452719 if district_name == "DON VALLEY"
replace enep = 2.473802 if district_name == "DONCASTER CENTRAL"
replace enep = 2.173814 if district_name == "DONCASTER NORTH"
replace enep = 2.416126 if district_name == "ROTHER VALLEY"
replace enep = 2.282109 if district_name == "ROTHERHAM"
replace enep = 1.970381 if district_name == "SHEFFIELD CENTRAL"
replace enep = 2.36001 if district_name == "SHEFFIELD ATTERCLIFFE"
replace enep = 1.87345 if district_name == "SHEFFIELD BRIGHTSIDE"
replace enep = 2.766062 if district_name == "SHEFFIELD HALLAM"
replace enep = 2.528006 if district_name == "SHEFFIELD HEELEY"
replace enep = 2.683632 if district_name == "SHEFFIELD HILLSBOROUGH"
replace enep = 2.04401 if district_name == "WENTWORTH"
replace enep = 2.643154 if district_name == "BATLEY & SPEN"
replace enep = 2.697015 if district_name == "BRADFORD NORTH"
replace enep = 2.705019 if district_name == "BRADFORD SOUTH"
replace enep = 2.397471 if district_name == "BRADFORD WEST"
replace enep = 2.823922 if district_name == "CALDER VALLEY"
replace enep = 3.040391 if district_name == "COLNE VALLEY"
replace enep = 2.641138 if district_name == "DEWSBURY"
replace enep = 2.609703 if district_name == "ELMET"
replace enep = 2.617599 if district_name == "HALIFAX"
replace enep = 1.986638 if district_name == "HEMSWORTH"
replace enep = 2.815209 if district_name == "HUDDERSFIELD"
replace enep = 2.710271 if district_name == "KEIGHLEY"
replace enep = 2.458616 if district_name == "LEEDS CENTRAL"
replace enep = 2.710121 if district_name == "LEEDS EAST"
replace enep = 2.842439 if district_name == "LEEDS NORTH EAST"
replace enep = 2.866465 if district_name == "LEEDS NORTH WEST"
replace enep = 2.82924 if district_name == "LEEDS WEST"
replace enep = 2.573072 if district_name == "LEEDS SOUTH & MORLEY"
replace enep = 2.575254 if district_name == "NORMANTON"
replace enep = 1.978984 if district_name == "PONTEFRACT & CASTLEFORD"
replace enep = 2.741973 if district_name == "PUDSEY"
replace enep = 2.714361 if district_name == "SHIPLEY"
replace enep = 2.484382 if district_name == "WAKEFIELD"
replace enep = 2.730615 if district_name == "CHESTER CITY OF"
replace enep = 2.633633 if district_name == "CONGLETON"
replace enep = 2.56184 if district_name == "CREWE & NANTWICH"
replace enep = 2.681588 if district_name == "EDDISBURY"
replace enep = 2.586163 if district_name == "ELLESMERE PORT & NESTON"
replace enep = 2.384234 if district_name == "HALTON"
replace enep = 2.415263 if district_name == "MACCLESFIELD"
replace enep = 2.504534 if district_name == "TATTON"
replace enep = 2.630937 if district_name == "WARRINGTON NORTH"
replace enep = 2.825961 if district_name == "WARRINGTON SOUTH"
replace enep = 2.526654 if district_name == "ALTRINCHAM & SALE"
replace enep = 2.551559 if district_name == "ASHTON-UNDER-LYNE"
replace enep = 2.527182 if district_name == "BOLTON NORTH EAST"
replace enep = 2.420858 if district_name == "BOLTON SOUTH EAST"
replace enep = 2.73859 if district_name == "BOLTON WEST"
replace enep = 2.448852 if district_name == "BURY NORTH"
replace enep = 2.523256 if district_name == "BURY SOUTH"
replace enep = 2.273361 if district_name == "CHEADLE"
replace enep = 2.758037 if district_name == "DAVYHULME"
replace enep = 2.578347 if district_name == "DENTON & REDDISH"
replace enep = 2.577043 if district_name == "ECCLES"
replace enep = 2.515256 if district_name == "HAZEL GROVE"
replace enep = 2.554812 if district_name == "HEYWOOD & MIDDLETON"
replace enep = 2.295453 if district_name == "LEIGH"
replace enep = 2.867369 if district_name == "LITTLEBOROUGH & SADDLEWORTH"
replace enep = 2.392236 if district_name == "MAKERFIELD"
replace enep = 1.93444 if district_name == "MANCHESTER CENTRAL"
replace enep = 2.544015 if district_name == "MANCHESTER BLACKLEY"
replace enep = 2.515539 if district_name == "MANCHESTER GORTON"
replace enep = 2.817532 if district_name == "MANCHESTER WITHINGTON"
replace enep = 2.356831 if district_name == "MANCHESTER WYTHENSHAWE"
replace enep = 2.630904 if district_name == "OLDHAM CENTRAL & ROYTON"
replace enep = 2.562941 if district_name == "OLDHAM WEST"
replace enep = 2.723662 if district_name == "ROCHDALE"
replace enep = 2.281173 if district_name == "SALFORD EAST"
replace enep = 2.545274 if district_name == "STALYBRIDGE & HYDE"
replace enep = 2.900016 if district_name == "STOCKPORT"
replace enep = 2.353093 if district_name == "STRETFORD"
replace enep = 2.183009 if district_name == "WIGAN"
replace enep = 2.613578 if district_name == "WORSLEY"
replace enep = 2.381914 if district_name == "BLACKBURN"
replace enep = 2.697549 if district_name == "BLACKPOOL NORTH"
replace enep = 2.696104 if district_name == "BLACKPOOL SOUTH"
replace enep = 2.630349 if district_name == "BURNLEY"
replace enep = 2.651003 if district_name == "CHORLEY"
replace enep = 2.235456 if district_name == "FYLDE"
replace enep = 2.642896 if district_name == "HYNDBURN"
replace enep = 2.758932 if district_name == "LANCASTER"
replace enep = 2.566715 if district_name == "MORECOMBE & LUNESDALE"
replace enep = 2.883707 if district_name == "PENDLE"
replace enep = 2.545925 if district_name == "PRESTON"
replace enep = 2.23419 if district_name == "RIBBLE VALLEY"
replace enep = 2.586666 if district_name == "ROSSENDALE & DARWEN"
replace enep = 2.694217 if district_name == "SOUTH RIBBLE"
replace enep = 2.596718 if district_name == "LANCASHIRE WEST"
replace enep = 2.599879 if district_name == "WYRE"
replace enep = 2.291116 if district_name == "BIRKENHEAD"
replace enep = 1.981605 if district_name == "BOOTLE"
replace enep = 2.673138 if district_name == "CROSBY"
replace enep = 1.883783 if district_name == "KNOWSLEY NORTH"
replace enep = 2.075683 if district_name == "KNOWSLEY SOUTH"
replace enep = 2.569897 if district_name == "LIVERPOOL BROADGREEN"
replace enep = 2.538833 if district_name == "LIVERPOOL GARSTON"
replace enep = 2.686528 if district_name == "LIVERPOOL MOSSLEY HILL"
replace enep = 1.760185 if district_name == "LIVERPOOL RIVERSIDE"
replace enep = 2.080771 if district_name == "LIVERPOOL WALTON"
replace enep = 2.052215 if district_name == "LIVERPOOL WEST DERBY"
replace enep = 2.315882 if district_name == "SOUTHPORT"
replace enep = 2.508127 if district_name == "ST HELENS NORTH"
replace enep = 2.473039 if district_name == "ST HELENS SOUTH"
replace enep = 2.627391 if district_name == "WALLASEY"
replace enep = 2.646391 if district_name == "WIRRAL SOUTH"
replace enep = 2.634684 if district_name == "WIRRAL WEST"
replace enep = 2.560561 if district_name == "BARROW & FURNESS"
replace enep = 2.69955 if district_name == "CARLISLE"
replace enep = 2.404954 if district_name == "COPELAND"
replace enep = 2.18488 if district_name == "PENRITH & THE BORDER"
replace enep = 2.303719 if district_name == "WESTMORLAND & LONSDALE"
replace enep = 2.36574 if district_name == "WORKINGTON"
replace enep = 2.695906 if district_name == "HARTLEPOOL"
replace enep = 2.769648 if district_name == "LANGBAURGH"
replace enep = 2.260837 if district_name == "MIDDLESBROUGH"
replace enep = 2.719556 if district_name == "REDCAR"
replace enep = 2.625311 if district_name == "STOCKTON NORTH"
replace enep = 2.993476 if district_name == "STOCKTON SOUTH"
replace enep = 2.624461 if district_name == "BISHOP AUCKLAND"
replace enep = 2.779305 if district_name == "DURHAM CITY OF"
replace enep = 2.474493 if district_name == "DARLINGTON"
replace enep = 1.944642 if district_name == "EASINGTON"
replace enep = 2.426509 if district_name == "DURHAM NORTH"
replace enep = 2.614139 if district_name == "DURHAM NORTH WEST"
replace enep = 2.395767 if district_name == "SEDGEFIELD"
replace enep = 2.569776 if district_name == "BERWICK-UPON-TWEED"
replace enep = 2.675153 if district_name == "BLYTH VALLEY"
replace enep = 2.640376 if district_name == "HEXHAM"
replace enep = 2.37308 if district_name == "WANSBECK"
replace enep = 2.65395 if district_name == "BLAYDON"
replace enep = 2.291857 if district_name == "GATESHEAD EAST"
replace enep = 2.304366 if district_name == "HOUGHTON & WASHINGTON"
replace enep = 2.108754 if district_name == "JARROW"
replace enep = 2.692786 if district_name == "NEWCASTLE UPON TYNE CENTRAL"
replace enep = 2.406957 if district_name == "NEWCASTLE UPON TYNE EAST"
replace enep = 2.858928 if district_name == "NEWCASTLE UPON TYNE NORTH"
replace enep = 2.35196 if district_name == "SOUTH SHIELDS"
replace enep = 2.401559 if district_name == "SUNDERLAND NORTH"
replace enep = 2.463053 if district_name == "SUNDERLAND SOUTH"
replace enep = 2.143255 if district_name == "TYNE BRIDGE"
replace enep = 2.70513 if district_name == "TYNEMOUTH"
replace enep = 2.399563 if district_name == "WALLSEND"
replace enep = 2.616039 if district_name == "ALYN & DEESIDE"
replace enep = 2.855748 if district_name == "CLWYD NORTH WEST"
replace enep = 3.384086 if district_name == "CLWYD SOUTH WEST"
replace enep = 2.828814 if district_name == "DELYN"
replace enep = 2.798875 if district_name == "WREXHAM"
replace enep = 3.690231 if district_name == "CARMARTHEN"
replace enep = 3.739306 if district_name == "CEREDIGION & PEMBROKE NORTH"
replace enep = 2.451071 if district_name == "LLANELLI"
replace enep = 3.009407 if district_name == "PEMBROKE"
replace enep = 1.67115 if district_name == "BLAENAU GWENT"
replace enep = 1.849134 if district_name == "ISLWYN"
replace enep = 2.775591 if district_name == "MONMOUTH"
replace enep = 2.662223 if district_name == "NEWPORT EAST"
replace enep = 2.564777 if district_name == "NEWPORT WEST"
replace enep = 2.37433 if district_name == "TORFAEN"
replace enep = 2.504158 if district_name == "CAERNARFON"
replace enep = 3.301164 if district_name == "CONWY"
replace enep = 3.438841 if district_name == "MEIRIONNYDD NANT CONWY"
replace enep = 3.028004 if district_name == "YNYS MON"
replace enep = 2.592423 if district_name == "BRIDGEND"
replace enep = 2.465781 if district_name == "CAERPHILLY"
replace enep = 1.964864 if district_name == "CYNON VALLEY"
replace enep = 1.693289 if district_name == "MERTHYR TYDFIL & RHYMNEY"
replace enep = 1.94067 if district_name == "OGMORE"
replace enep = 2.54151 if district_name == "PONTYPRIDD"
replace enep = 1.789991 if district_name == "RHONDDA"
replace enep = 3.05784 if district_name == "BRECON & RADNOR"
replace enep = 2.644461 if district_name == "MONTGOMERY"
replace enep = 3.049392 if district_name == "CARDIFF CENTRAL"
replace enep = 2.885494 if district_name == "CARDIFF NORTH"
replace enep = 2.660988 if district_name == "CARDIFF SOUTH & PENARTH"
replace enep = 2.722407 if district_name == "CARDIFF WEST"
replace enep = 2.720761 if district_name == "VALE OF GLAMORGAN"
replace enep = 2.028041 if district_name == "ABERAVON"
replace enep = 2.756526 if district_name == "GOWER"
replace enep = 2.214339 if district_name == "NEATH"
replace enep = 2.156012 if district_name == "SWANSEA EAST"
replace enep = 2.710344 if district_name == "SWANSEA WEST"
replace enep = 2.56056 if district_name == "ROXBURGH & BERWICKSHIRE"
replace enep = 2.791707 if district_name == "TWEEDDALE ETTRICK & LAUDERDALE"
replace enep = 2.735509 if district_name == "CLACKMANNAN"
replace enep = 2.729205 if district_name == "FALKIRK EAST"
replace enep = 2.800143 if district_name == "FALKIRK WEST"
replace enep = 3.213034 if district_name == "STIRLING"
replace enep = 3.43515 if district_name == "DUMFRIES"
replace enep = 3.326459 if district_name == "GALLOWAY & UPPER NITHSDALE"
replace enep = 2.793875 if district_name == "FIFE CENTRAL"
replace enep = 2.163989 if district_name == "DUNFERMLINE EAST"
replace enep = 3.058713 if district_name == "DUNFERMLINE WEST"
replace enep = 2.983223 if district_name == "KIRKCALDY"
replace enep = 2.627513 if district_name == "FIFE NORTH EAST"
replace enep = 2.713754 if district_name == "ABERDEEN NORTH"
replace enep = 3.211905 if district_name == "ABERDEEN SOUTH"
replace enep = 2.774537 if district_name == "BANFF & BUCHAN"
replace enep = 2.742886 if district_name == "GORDON"
replace enep = 3.05919 if district_name == "KINCARDINE & DEESIDE"
replace enep = 3.003265 if district_name == "MORAY"
replace enep = 2.85436 if district_name == "CAITHNESS & SUTHERLAND"
replace enep = 3.639255 if district_name == "INVERNESS NAIRN & LOCHABER"
replace enep = 3.000958 if district_name == "ROSS CROMARTY AND SKYE"
replace enep = 2.938788 if district_name == "EAST LOTHIAN"
replace enep = 3.149529 if district_name == "EDINBURGH CENTRAL"
replace enep = 2.876516 if district_name == "EDINBURGH EAST"
replace enep = 2.955817 if district_name == "EDINBURGH LEITH"
replace enep = 3.314692 if district_name == "EDINBURGH PENTLANDS"
replace enep = 3.229704 if district_name == "EDINBURGH SOUTH"
replace enep = 3.191528 if district_name == "EDINBURGH WEST"
replace enep = 3.086453 if district_name == "LINLITHGOW"
replace enep = 3.260264 if district_name == "LIVINGSTON"
replace enep = 3.067821 if district_name == "MIDLOTHIAN"
replace enep = 3.385648 if district_name == "ARGYLL & BUTE"
replace enep = 2.988213 if district_name == "AYR"
replace enep = 2.368393 if district_name == "CARRICK, CUMNOCK & DOON VALLEY"
replace enep = 2.587807 if district_name == "CLYDEBANK & MILNGAVIE"
replace enep = 3.2339 if district_name == "CLYDESDALE"
replace enep = 2.38507 if district_name == "CUMBERNAULD & KILSYTH"
replace enep = 2.971555 if district_name == "CUNNINGHAME NORTH"
replace enep = 2.365281 if district_name == "CUNNINGHAME SOUTH"
replace enep = 3.149022 if district_name == "DUMBARTON"
replace enep = 2.995043 if district_name == "EAST KILBRIDE"
replace enep = 3.337054 if district_name == "EASTWOOD"
replace enep = 2.813488 if district_name == "GLASGOW CATHCART"
replace enep = 2.202657 if district_name == "GLASGOW CENTRAL"
replace enep = 2.027506 if district_name == "GLASGOW GARSCADDEN"
replace enep = 2.172793 if district_name == "GLASGOW GOVAN"
replace enep = 3.007294 if district_name == "GLASGOW HILLHEAD"
replace enep = 2.099983 if district_name == "GLASGOW MARYHILL"
replace enep = 2.260701 if district_name == "GLASGOW POLLOK"
replace enep = 1.793657 if district_name == "GLASGOW PROVAN"
replace enep = 2.544374 if district_name == "GLASGOW RUTHERGLEN"
replace enep = 2.229047 if district_name == "GLASGOW SHETTLESTON"
replace enep = 1.767552 if district_name == "GLASGOW SPRINGBURN"
replace enep = 2.186837 if district_name == "GREENOCK & PORT GLASGOW"
replace enep = 2.435885 if district_name == "HAMILTON"
replace enep = 3.071034 if district_name == "KILMARNOCK & LOUDOUN"
replace enep = 2.350182 if district_name == "MONKLANDS EAST"
replace enep = 2.289269 if district_name == "MONKLANDS WEST"
replace enep = 2.056026 if district_name == "MOTHERWELL NORTH"
replace enep = 2.517181 if district_name == "MOTHERWELL SOUTH"
replace enep = 2.669348 if district_name == "PAISLEY NORTH"
replace enep = 2.634716 if district_name == "PAISLEY SOUTH"
replace enep = 3.394342 if district_name == "RENFREW WEST & INVERCLYDE"
replace enep = 3.25134 if district_name == "STRATHKELVIN & BEARSDEN"
replace enep = 2.859267 if district_name == "ANGUS EAST"
replace enep = 2.784219 if district_name == "DUNDEE EAST"
replace enep = 2.804329 if district_name == "DUNDEE WEST"
replace enep = 2.952294 if district_name == "TAYSIDE NORTH"
replace enep = 3.483565 if district_name == "PERTH & KINROSS"
replace enep = 3.45464 if district_name == "ORKNEY & SHETLAND"
replace enep = 3.196154 if district_name == "WESTERN ISLES"
replace enep = 2.048989 if district_name == "BELFAST EAST"
replace enep = 4.302223 if district_name == "BELFAST NORTH"
replace enep = 2.499563 if district_name == "BELFAST SOUTH"
replace enep = 2.994663 if district_name == "BELFAST WEST"
replace enep = 1.728411 if district_name == "ANTRIM EAST"
replace enep = 2.380649 if district_name == "LONDONDERRY EAST"
replace enep = 3.246331 if district_name == "FERMANAGH AND SOUTH TYRONE"
replace enep = 2.832466 if district_name == "FOYLE"
replace enep = 1.929132 if district_name == "LAGAN VALLEY"
replace enep = 3.099284 if district_name == "MID-ULSTER"
replace enep = 2.569637 if district_name == "NEWRY AND ARMAGH"
replace enep = 2.012928 if district_name == "ANTRIM  NORTH"
replace enep = 1.455861 if district_name == "DOWN NORTH"
replace enep = 1.909209 if district_name == "ANTRIM SOUTH"
replace enep = 2.313086 if district_name == "DOWN SOUTH"
replace enep = 1.614655 if district_name == "STRANGFORD"
replace enep = 2.317506 if district_name == "UPPER BANN"


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

tostring dymth, gen(dmy)

replace dmy = dmy + "1987"

replace dmy = "0" + dmy if strlen(dmy)==7

destring dmy, gen(intdate)

gen surveydate = date(string(intdate,"%8.0f"),"DMY")

format %tdMon_DD,_CCYY surveydate

gen edate = 19870611

gen electiondate = date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate + 1

replace time = . if time < 0

* Gender

egen male = rowmax(rsex qk22 qk22sex q64b)

recode male 2=0

* Age

egen age = rowmax(rage qk21 qk21age q56)

recode age 99=.

* Education

gen education = hedqual

recode education 6=. 7=6 8=. 

replace education = 7 - education

* Interest for election

gen election_interest = qa2

recode election_interest (9=.)

replace election_interest = 5 - election_interest

* Party identification (national)

gen pid = qc100p
recode pid 4=3 5=3

gen partycloser = qc100ln
recode partycloser 4=3 5=3

gen pidstatus_whole = .

replace pidstatus_whole = 2 if pid == 8 & partycloser == 8 | pid == 8 & partycloser == 9

replace pidstatus_whole = 3 if pid == 1 & pidstatus_whole!=2
replace pidstatus_whole = 3 if partycloser == 1 & pidstatus_whole!=2

replace pidstatus_whole = 1 if pid!=1 & pidstatus_whole!=2 & pidstatus_whole!=3 & pid!=.
replace pidstatus_whole = 1 if partycloser!=1 & pidstatus_whole!=2 & pidstatus_whole!=3 & partycloser!=.

label define pidstatus 1 "Loser PID" 2 "No PID" 3 "Winner PID"
label values pidstatus_whole pidstatus

* Party identification scale (national)

gen pidscale_whole = .

replace pidscale_whole = 1 if pidstatus_whole == 1 & qc100s == 1
replace pidscale_whole = 2 if pidstatus_whole == 1 & qc100s == 2
replace pidscale_whole = 3 if pidstatus_whole == 1 & qc100s == 3
replace pidscale_whole = 4 if pidstatus_whole == 2
replace pidscale_whole = 5 if pidstatus_whole == 3 & qc100s == 3
replace pidscale_whole = 6 if pidstatus_whole == 3 & qc100s == 2
replace pidscale_whole = 7 if pidstatus_whole == 3 & qc100s == 1

label define pidscale 1 "Strong loser PID" 2 "Moderate loser PID" 3 "Weak loser PID" 4 "No PID" 5 "Weak winner PID" 6 "Moderate winner PID" 7 "Strong winner PID" 
label values pidscale_whole pidscale

* Follow politics regularly on TV

gen tv1 = qh12b1
gen tv2 = qh12b2
gen tv3 = qh12b3
gen tv4 = qh12b4
gen tv5 = qh12b5
gen tv6 = qh12b6
gen tv7 = qh12i1
gen tv8 = qh12i2
gen tv9 = qh12i3
gen tv10 = qh12i4
gen tv11 = qh12i5
gen tv12 = qh12i6

recode tv1 2=0 9=.
recode tv2 2=0 9=.
recode tv3 2=0 9=.
recode tv4 2=0 9=.
recode tv5 2=0 9=.
recode tv6 2=0 9=.
recode tv7 2=0 9=.
recode tv8 2=0 9=.
recode tv9 2=0 9=.
recode tv10 2=0 9=.
recode tv11 2=0 9=.
recode tv12 2=0 9=.

gen tv = max(tv1, tv2, tv3, tv4, tv5, tv6, tv7, tv8, tv9, tv10, tv11, tv12)

* Follow politics regularly on radio

gen radio1 = qh12r1
gen radio2 = qh12r2
gen radio3 = qh12r3
gen radio4 = qh12r4

recode radio1 2=0 9=.
recode radio2 2=0 9=.
recode radio3 2=0 9=.
recode radio4 2=0 9=.

gen radio = max(radio1, radio2, radio3, radio4)

* Follow politics regularly in newspaper

gen press = readpap

recode press 2=0 9=.

* Political discussion

gen discussion = qa1

recode discussion (9=.)

replace discussion = discussion - 1

gen discussion_3pts = discussion

replace discussion_3pts = 0 if discussion == 1
replace discussion_3pts = 1 if discussion == 2
replace discussion_3pts = 2 if discussion == 3

* Number of close friends

gen friends = pals

recode friends -9=. 9=.

* Number of close friends at work

gen coworkers = wrkpals

recode coworkers -9=. 9=.

* Number of close friends among neighbours

gen neighbours = nbrpals

recode neighbours -9=. 9=.

* Size

gen size = friends + coworkers + neighbours

* Social contact

gen contact = palvisit

recode contact -1=8 9=. 1=2

replace contact = contact - 1

replace contact = 7 - contact

* Care about outcome

gen care_whole = q1

recode care_whole 9=. 2=0


*********************************
** NATIONAL-LEVEL EXPECTATIONS ** 
*********************************

gen con_chance_whole = qd2c // Conservative party's probability of winning the election
gen lab_chance_whole = qd2l // Labour party's probability of winning the election
gen all_chance_whole = qd2a // Alliance's probability of winning the election

recode con_chance_whole 9=.
recode lab_chance_whole 9=.
recode all_chance_whole 9=.

replace con_chance_whole = 4 - con_chance_whole
replace lab_chance_whole = 4 - lab_chance_whole
replace all_chance_whole = 4 - all_chance_whole

* Generate variable identifying incomplete answers

gen complete_whole = 0 if con_chance_whole == . | lab_chance_whole == . | all_chance_whole == .
replace complete_whole = 1 if con_chance_whole!=. & lab_chance_whole!=. & all_chance_whole!=.

* Generate value of 1 if the expectation for one party is higher or equal to the expectations for at least one other party

gen con_whole = 1 if con_chance_whole >= lab_chance_whole & con_chance_whole >= all_chance_whole & complete_whole == 1

gen lab_whole = 1 if lab_chance_whole >= con_chance_whole & lab_chance_whole >= all_chance_whole & complete_whole == 1

gen all_whole = 1 if all_chance_whole >= lab_chance_whole & all_chance_whole >= con_chance_whole & complete_whole == 1

gen oth_whole = 1 if lab_chance_whole == 0 & con_chance_whole == 0 & all_chance_whole == 0 & complete_whole == 1

replace lab_whole = . if oth_whole == 1 & complete_whole == 1
replace con_whole = . if oth_whole == 1 & complete_whole == 1
replace all_whole = . if oth_whole == 1 & complete_whole == 1

* Generate variable for ambiguous forecasts

gen ambiguous_whole = .

replace ambiguous_whole = 99 if con_whole == lab_whole & con_whole!=. & complete_whole == 1 | con_whole == all_whole & con_whole!=. & complete_whole == 1

replace ambiguous_whole = 99 if lab_whole == con_whole & lab_whole!=. & complete_whole == 1 | lab_whole == all_whole & lab_whole!=. & complete_whole == 1

replace ambiguous_whole = 99 if all_whole == lab_whole & all_whole!=. & complete_whole == 1 | all_whole == con_whole & all_whole!=. & complete_whole == 1

* Generate value of 0 for lower expectations

replace con_whole = 0 if con_whole!=1 & con_whole!=. & complete_whole == 1
replace lab_whole = 0 if lab_whole!=1 & lab_whole!=. & complete_whole == 1
replace all_whole = 0 if all_whole!=1 & all_whole!=. & complete_whole == 1
replace oth_whole = 0 if oth_whole!=1 & oth_whole!=. & complete_whole == 1

* Forecasts (1 = Labour, 2 = Conservative, 3 = Liberal Democrat, 10 = other, 99 = ambiguous)

gen forecast_whole = .

replace forecast_whole = 1 if con_whole == 1 & complete_whole == 1
replace forecast_whole = 2 if lab_whole == 1 & complete_whole == 1 
replace forecast_whole = 3 if all_whole == 1 & complete_whole == 1
replace forecast_whole = 10 if oth_whole == 1 & complete_whole == 1
replace forecast_whole = 99 if ambiguous_whole == 99 & complete_whole == 1

* Identify correct and ambiguous forecasts

gen correct_whole = 0 if forecast_whole!=1 & forecast_whole!=99 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 1 if forecast_whole == 1 & forecast_whole!=99 & forecast_whole!=. & complete_whole == 1
replace correct_whole = 99 if forecast_whole == 99 & complete_whole == 1

* Generate dichotomous variable (treat ambiguous forecasts as incorrect)

gen correct_whole_d = correct_whole

replace correct_whole_d = 0 if correct_whole_d == 99
replace correct_whole_d = 1 if correct_whole_d == 1


**********
** SAVE **
**********

save "gb1987_bes.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion pidscale_whole election_interest age i.male time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Seat majority (DV)"
label variable discussion "Discussion"
label variable size "Network size"
label variable pidscale_whole "National PID"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable election_interest "Interest"
label variable care_whole "Caring about outcome"
label variable time "Time of interview"

quietly logistic correct_whole_d discussion pidscale_whole election_interest age i.male time

estpost tabstat correct_whole_d discussion pidscale_whole election_interest age male time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "gb1987_bes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.1f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1987 British general election (BES), national level") replace

eststo clear

log close